sqlserver(1)-table name and field information lookup

1、查看表的所有字段注释
SELECT
A.name AS table_name,
B.name AS column_name,
C.value AS column_description
FROM sys.tables A
INNER JOIN sys.columns B ON B.object_id = A.object_id
LEFT JOIN sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id
WHERE A.name = ‘表名’;

2. Query table name and list information
select * from INFORMATION_SCHEMA.COLUMNS;
select * from sys.columns;

Compared with INFORMATION_SCHEMA.columns and sys.columns, INFORMATION_SCHEMA.columns is more recommended.
Because INFORMATION_SCHEMA.columns conforms to the ISO standard, and things like sys.columns are proprietary things made by Microsoft itself.
In fact, both INFORMATION_SCHEMA.columns and sys.columns are essentially views. Under the premise that the two are essentially the same, we recommend conforming to the ISO standard, so that this experience can also be consistent with the experience of other databases.

3. View all table names and all field names
sysobjects and syscolumns in SQL to
view all table names:
select name from sysobjects where type='U' to
query all field names of the table:
Select name from syscolumns Where ID=OBJECT_ID('table name' )

4. sys.objects finds the content of each object
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_39597541/article/details/112536844