SQL Server Getting the decriptions of the tables and columns via a sql statement

jdgnovmf  于 2023-03-28  发布在  其他
关注(0)|答案(5)|浏览(128)

I have a database and a lot of tables inside it. I wrote some information into the each table and column's decription part. And now using query i want to see all table and columns descriptions.

Note: DATABASE -> ms sql server

Can you please help me ?

vof42yt1

vof42yt11#

You can see that using INFORMATION_SCHEMA

To get columns for each table you can do:

SELECT * FROM INFORMATION_SCHEMA.COLUMNS

To get table information you can do:

SELECT * FROM INFORMATION_SCHEMA.TABLES
hof1towb

hof1towb2#

Check this query:

SELECT 
    t.name AS TableName 
  , td.value AS TableDescription
  , c.name AS ColumnName
  , cd.value AS ColumnDescription
FROM sys.tables t
INNER JOIN sys.columns c ON t.object_id = c.object_id
LEFT JOIN sys.extended_properties td 
    ON td.major_id = t.object_id
    AND td.minor_id = 0
    AND td.name = 'MS_Description'
LEFT JOIN sys.extended_properties cd 
    ON cd.major_id = t.object_id
    AND cd.minor_id = c.column_id
    AND cd.name = 'MS_Description'
uz75evzq

uz75evzq3#

select * from INFORMATION_SCHEMA.TABLES
select * from INFORMATION_SCHEMA.COLUMNS
jgwigjjp

jgwigjjp4#

select * from user_col_comments;

This will display all tables's column with comments for the logged in user.

select * from user_col_comments where table_name = '<table name>';

This will display specified tables's column with comments for the logged in user.

mm9b1k5b

mm9b1k5b5#

desc table_name query is used to describe the table

相关问题