SQL SERVER 查询表的字段名、数据类型和最大长度

时间:2022-04-17 13:48:20

查询表的字段名、数据类型和最大长度:

 USE test2   --数据库test2,表fruits;
GO
SELECT syscolumns.name AS 字段名,systypes.name AS 数据类型,syscolumns.length AS 长度
FROM syscolumns INNER JOIN systypes ON systypes.xtype=syscolumns.xtype
WHERE id=(SELECT id FROM sysobjects WHERE name='fruits')

SELECT sys.all_columns.name as aa, max_length as bb
FROM sys.all_columns
INNER JOIN sysobjects ON sysobjects.id=sys.all_columns.object_id
WHERE sysobjects.xtype='u' AND sysobjects.name='fruits'

SQL SERVER 查询表的字段名、数据类型和最大长度