MsSql中获取表结构(字段名,类型,长度)

发布于 2018-03-22  141 次阅读


SELECT a.name AS tablename, b.name AS colName, c.name AS colType, c.length AS colLength
FROM sys.sysobjects AS a INNER JOIN
 sys.syscolumns AS b ON a.id = b.id AND a.xtype = 'U' INNER JOIN
 sys.systypes AS c ON b.xtype = c.xusertype where tablename='表名'

可以去掉where条件保存为视图方便查询使用。


LoneKing