Obtains whether all columns in the database and whether the column type is null, whether the default value is a primary key, and whether the default value of the database is

Source: Internet
Author: User

Obtains whether all columns in the database and whether the column type is null, whether the default value is a primary key, and whether the default value of the database is

Read the summary of the stored procedures of SQL Server

SELECT DISTINCT c.name AS tablename, a.name,a.is_nullable,dbo.GetRemoveParentheses(d.text) AS defaultvalue,CASE WHEN (a.name = index_col (c.name, f.index_id,  1) or         a.name = index_col (c.name, f.index_id,  2) or         a.name = index_col (c.name, f.index_id,  3) or         a.name = index_col (c.name, f.index_id,  4) or         a.name = index_col (c.name, f.index_id,  5) or         a.name = index_col (c.name, f.index_id,  6) or         a.name = index_col (c.name, f.index_id,  7) or         a.name = index_col (c.name, f.index_id,  8) or         a.name = index_col (c.name, f.index_id,  9) or         a.name = index_col (c.name, f.index_id, 10) or         a.name = index_col (c.name, f.index_id, 11) or         a.name = index_col (c.name, f.index_id, 12) or         a.name = index_col (c.name, f.index_id, 13) or         a.name = index_col (c.name, f.index_id, 14) or         a.name = index_col (c.name, f.index_id, 15) or         a.name = index_col (c.name, f.index_id, 16)) THEN 1 ELSE 0 END AS isPrimary ,        CASE a.precision          WHEN 0          THEN CASE a.is_ansi_padded                 WHEN 1                 THEN CONVERT(NVARCHAR(15), b.name + '('                      + CONVERT(NVARCHAR(10), a.max_length) + ')')                 WHEN 0 THEN b.name               END          ELSE CASE a.scale                 WHEN 0 THEN b.name                 ELSE b.name + '(' + CONVERT(NVARCHAR(10), a.precision) + ','                      + CONVERT(NVARCHAR(10), a.scale) + ')'               END        END AS typelength FROM  sys.columns a        LEFT JOIN sys.types b ON a.system_type_id = b.system_type_id                                 AND a.user_type_id = b.user_type_idINNER JOIN sysobjects c ON c.id = a.object_idLEFT JOIN syscomments d ON d.id = a.default_object_idINNER JOIN sys.key_constraints e ON e.parent_object_id = a.object_idINNER JOIN sys.indexes f ON e.unique_index_id = f.index_idWHERE c.xtype = 'u' AND f.is_primary_key = 1  


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.