SQL server中怎么查询建表语句用命令
时间: 2024-06-03 20:09:31 浏览: 72
您可以使用以下命令查询 SQL Server 中的建表语句:
EXEC sp_help 'table_name'
其中,'table_name'替换为您想要查询的表名称。
另外,您还可以通过以下脚本查询表创建语句:
SELECT SYSOBJECTS.[name] AS Table_Name,
SYS.columns.[name] AS Column_Name,
systypes.[name] AS Data_Type,
SYS.columns.[length] AS Length,
SYS.columns.[precision] AS Precision,
syscomments.[text] AS Default_Value,
SYS.columns.isnullable AS Nullable
FROM SYS.objects
INNER JOIN SYS.columns
ON SYS.objects.[object_id] = SYS.columns.[object_id]
INNER JOIN systypes
ON SYS.columns.system_type_id = systypes.system_type_id
LEFT JOIN syscomments
ON SYS.columns.default_object_id = syscomments.id
WHERE SYS.objects.[type] = 'U'
AND SYS.objects.[name] = 'table_name'
ORDER BY SYS.objects.[name],
SYS.columns.column_id
同样,'table_name'替换为您想要查询的表名称。
阅读全文