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