SQL statements for viewing data tables and fields (applicable to SQLServer2000)

Source: Internet
Author: User

After analyzing the SQLServer2000 system table, the following two SQL statements are written. You can create two "views" for the two statements to view the user data table and field information.

1. List all user data tables:

Select top 100 PERCENT o. name AS table name
FROM dbo. syscolumns c INNER JOIN
Dbo. sysobjects o ON o. id = c. id AND objectproperty (o. id, N 'isusertable') = 1 AND
O. name <> 'dtproperties' LEFT OUTER JOIN
Dbo. sysproperties m ON m. id = o. id AND m. smallid = c. colorder
WHERE (c. colid = 1)
Order by o. name, c. colid

2. List all user data tables and their field information:

Select top 100 PERCENT c. colid AS No., o. name AS table name, c. name AS column name,
T. name AS type, c. length AS length, c. isnullable AS can be empty,
CAST (m. [value] AS Varchar (100) AS description
FROM dbo. syscolumns c INNER JOIN
Dbo. sysobjects o ON o. id = c. id AND objectproperty (o. id, N 'isusertable') = 1 AND
O. name <> 'dtproperties' INNER JOIN
Dbo. policypes t ON t. xusertype = c. xusertype LEFT OUTER JOIN
Dbo. sysproperties m ON m. id = o. id AND m. smallid = c. colorder
Order by o. name, c. colid

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.