SQL Server gets all the columns

Source: Internet
Author: User

Target database for Microsoft Strength Database: AdventureWorks2012

1. SQL Statements:

SELECT DISTINCTC.table_schema, C.table_name, C.column_name, C.data_type, C.is_nullable, Tc. Constraint_type,CONVERT(INT, C.numeric_precision) Numeric_precision, C.numeric_scale, C.character_maximum_length, C.ordinal_position, Tc.CON Straint_name,ColumnProperty(object_id(C.table_schema+ '.' +c.table_name), C.column_name,'isidentity') isidentity, (SELECT     Case  when COUNT(1)= 0  Then 0                         ELSE 1                    END           frominformation_schema. Table_constraints xINNER JOINInformation_schema. Constraint_column_usage Ccux onC.table_name=Ccux. TABLE_NAME andC.column_name=Ccux. column_name andC.table_schema=Ccux. Table_schemaWHEREX.constraint_type= 'UNIQUE'                     andX.table_schema=Ccux. Table_schema andX.constraint_name=Ccux. constraint_name) IsUnique frominformation_schema. COLUMNS C Left OUTER JOIN(INFORMATION_SCHEMA. Constraint_column_usage CCUJOINInformation_schema. Table_constraints TC on(TC. Table_schema=CCU. Table_schema andTc. Constraint_name=CCU. Constraint_name and  notTc. Constraint_typeinch (                                                              'CHECK',                                                              'UNIQUE' )                                                              )                        )  on(C.table_schema=CCU. Table_schema andC.table_name=CCU. TABLE_NAME andC.column_name=CCU. COLUMN_NAME)ORDER  byC.table_schema, C.table_name, C.column_name;

2. Results:

SQL Server gets all the columns

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.