SQL Server queries the basic information of a column, including the table name, column name, data type, remarks, maximum width, increment, empty, and primary key.

Source: Internet
Author: User

Select B. Name as tablename, A. Name columnname, C. Name as datatype, P. value as description, A. max_length as maxlength
, (Case A. is_identity when 1 then 'true' else 'false' end) as [identity]
, (Case A. is_nullable when 1 then 'true' else' false' end) as [isnull]
, (Case K. type when 'pk' then 'true' else 'false' end) as [iskey]
From SYS. Objects B
Inner join SYS. columns A on A. object_id = B. object_id
Left join SYS. Types C on A. system_type_id = C. user_type_id
Left join SYS. extended_properties P on p. major_id = A. object_id and P. minor_id = A. column_id and P. Name = 'Ms _ description'
Left join information_schema.constraint_column_usage SCC on SCC. table_name = B. Name and SCC. column_name = A. Name
Left join SYS. Objects K on K. Name = SCC. constraint_name and K. type = 'pk'
Where B. type = 'U' and A. Name = 'id'

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.