在动态编程中,我们需要获取表的结构数据,如表名,数据类型,精度等数据。你可以参考下面几行代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
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