sqlserver查询表字段结构脚本
时间: 2023-07-18 19:07:06 浏览: 100
可以使用以下 T-SQL 脚本获取 SQL Server 数据库中表的字段结构:
```
SELECT
c.name AS '列名',
t.Name AS '数据类型',
c.max_length AS '最大长度',
c.is_nullable AS '可空',
ISNULL(i.is_primary_key, 0) AS '主键'
FROM
sys.columns c
INNER JOIN
sys.types t ON c.user_type_id = t.user_type_id
LEFT OUTER JOIN
sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id
LEFT OUTER JOIN
sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id
WHERE
c.object_id = OBJECT_ID('表名')
```
将 `表名` 替换为你要查询的表名,并执行该脚本即可。
阅读全文