SQL statement used to query the field information of the SQL Server table

Source: Internet
Author: User
    1. -- Query table description
    2. Select a. ID, A. Name, B. value from sysobjects
    3. Left join sysproperties B on A. ID = B. ID
    4. Where a. Name = 'userinfo'

  1. Select
  2. -- Table name = case when a. colorder = 1 then D. Name else ''end,
  3. -- Table description = case when a. colorder = 1 then isnull (F. Value, '') else'' end,
  4. FIELD No. = A. colorder,
  5. Field name = A. Name,
  6. Id = case when columnproperty (A. ID, A. Name, 'isidentity ') = 1 then' √ 'else' end,
  7. Primary Key = case when exists (select 1 from sysobjects where xtype = 'pk' and name in (
  8. Select name from sysindexes where indid in (
  9. Select indid from sysindexkeys where id = A. ID and colid = A. colid
  10. ) Then' √ 'else' end,
  11. Type = B. Name,
  12. Bytes occupied = A. length,
  13. Length = columnproperty (A. ID, A. Name, 'precision '),
  14. Decimal places = isnull (columnproperty (A. ID, A. Name, 'Scale'), 0 ),
  15. Allow null = case when a. isnullable = 1 then '√ 'else' 'end,
  16. Default Value = isnull (E. Text ,''),
  17. Field description = isnull (G. [value], '')
  18. From syscolumns
  19. Left join policypes B on A. xtype = B. xusertype
  20. Inner join sysobjects D on A. ID = D. id and D. xtype = 'U'
  21. Left join syscomments e on A. cdefault = E. ID
  22. Left join sysproperties g on A. ID = G. ID and A. colid = G. smallid
  23. Left join sysproperties F on D. id = f. ID and F. smallid = 0
  24. Where D. Name = 'table name' -- if only the specified table is queried, add this condition.
  25. Order by A. ID, A. colorder

If you want to create an SQL Server tool and find the SQL above, you can write it down.

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.