获取表的结构数据

在动态编程中,我们需要获取表的结构数据,如表名,数据类型,精度等数据。你可以参考下面几行代码:

 

DECLARE @table_Name SYSNAME = 'Q'


SELECT t.TABLE_NAME, 
       c.COLUMN_NAME, 
       c.DATA_TYPE, 
       c.NUMERIC_PRECISION,
       c.NUMERIC_SCALE,
       ISNULL(CHARACTER_MAXIMUM_LENGTH,0 ) AS SIZE
FROM INFORMATION_SCHEMA.TABLES AS t
INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON 
    (t.TABLE_NAME = c.TABLE_NAME) 
WHERE t.TABLE_NAME= @table_Name
ORDER BY t.TABLE_NAME
Source Code

 

posted @ 2019-05-15 16:48 Insus.NET 阅读(...) 评论(...) 编辑 收藏