View the primary key of a table in a library, identify columns, computed columns, field types, allow nulls, default values, and other properties

Source: Internet
Author: User

View the primary key of a table in a library, identify columns, computed columns, field types, allow nulls, default values, and other properties

            SELECT            [Table name]= Case  whent.column_id= 1  Then object_nameT.object_id)ELSE "' END ,            [Field Number]=t.column_id,[Field name]=T.name,[PRIMARY Key]= Case  when exists(SELECT 1  fromSys.key_constraintswhereType='PK'  and object_id=T.object_id) Then '●' ELSE "' END,            [identity Column]= CaseT.is_identity when 1  Then '●' ELSE "' END,            [Computed Columns]= Caset.is_computed when 1  Then '●' ELSE "' END,            [field Type]=(SELECTName fromSys.typesWHEREuser_type_id=t.user_type_id),[Field Length]=T.PRECISION,            [Decimal digits] =T.scale,[Allow empty] =  CaseT.is_nullable when 1  Then '●' ELSE "' END,            [Default Value]= ISNULL((SELECTDefinition fromSys.default_constraintswhere object_id =T.DEFAULT_OBJECT_ID),"'),            [Field Description]=(SELECTVALUE fromSys.extended_propertiesWHEREmajor_id=T.object_id  andminor_id=t.column_id) fromsys. COLUMNS TINNER JOINSys.objects O onT.object_id =O.object_id  andO.type= 'U'            WHERE  Right(object_nameT.object_id),3)<> 'Log'  and object_nameT.object_id)<>'auditddlevents'  and object_nameT.object_id)<>'dtproperties'            ORDER  by object_nameT.object_id), t.column_id

View the primary key of a table in a library, identify columns, computed columns, field types, allow nulls, default values, and other properties

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.