Database Skills: A Very Practical Script to Organize SQL Server

Today, I will share with you some commonly used scripts of SQL Server that I use in my work. I hope it can be helpful to everyone!

1. Query all table structures of the database

Through this script, you can quickly find table fields, or generate database design documents, and compare databases.

SELECT obj.name 表名,
col.colorder AS 序号 ,
col.name AS 列名 ,
ISNULL(ep.[value], '') AS 列说明 ,
t.name AS 数据类型 ,
CASE WHEN col.isnullable = 1 THEN '1'
ELSE ''
END AS 允许空 ,
ISNULL(comm.text, '') AS 默认值,
Coalesce(epTwo.value, '') AS documentation
FROM dbo.syscolumns col
LEFT JOIN dbo.systypes t ON col.xtype = t.xusertype
inner JOIN dbo.sysobjects obj ON col.id = obj.id
AND obj.xtype = 'U'
AND obj.status >= 0
LEFT JOIN dbo.sysco

Guess you like

Origin blog.csdn.net/xishining/article/details/111188838