SQL statement used to query the table structure

Source: Internet
Author: User

If you need to query the table structure, can the SQL statement be implemented? The following describes how to write SQL statements to query the table structure. It is helpful for you to learn SQL statements.

  1. -- Query non-system databases
  2. Select name FROM Master .. SysDatabases where dbid> 4
  3.  
  4. -- Select all tables in the water database
  5. Use [water] SELECT name FROM sysobjects WHERE xtype = 'U' Or xtype = 'S'
  6.  
  7. -- Select all user tables in the water database
  8. Use [water] SELECT name FROM sysobjects WHERE xtype = 'U' and objectproperty (id, 'ismsshipped ') = 0
  9.  
  10. -- Query the field name, length, type, and field description of the admin table in the water database.
  11. Use [water] SELECT. [name] as 'field name',. length 'length', c. [name] 'type', e. value as 'field description' FROM syscolumns
  12. Left join policypes B on a. xusertype = B. xusertype
  13. Left join policypes c on a. xtype = c. xusertype
  14. Inner join sysobjects d on a. id = d. id and d. xtype = 'U'
  15. Left join sys. extended_properties e on a. id = e. major_id and a. colid = e. minor_id and e. name = 'Ms _ description'
  16. Where d. name = 'admin'

 

 

 

[Edit recommendations]

Use SQL statements to query consecutive segments

SQL statement writing for multi-condition query in a single table

Use SQL statements to query Time Periods

Use SQL statements to delete duplicate records

Example of batch SQL statement execution

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.