首页 > 代码库 > SQL Server2008中通过SQL获取表结构
SQL Server2008中通过SQL获取表结构
SQL Server2008中通过SQL获取表结构
新增数据用户,角色为public。映射到待获取表结构的数据库上,授与用户在该数据库上的身份为db_owner
运行例如以下SQL语句:
select syscolumns.name as [Name] , systypes.name as [Type], syscolumns.length AS [Size], syscolumns.xprec As [Precision], ISNULL(syscolumns.scale, 0) AS [Scale], sys.extended_properties.value as [Mark], syscolumns.isnullable as [NULL], (Case when exists( select 1 from sysobjects inner join sysindexes on sysindexes.name = sysobjects.name inner join sysindexkeys on sysindexes.id = sysindexkeys.id and sysindexes.indid = sysindexkeys.indid where xtype=‘PK‘ and parent_obj = syscolumns.id and sysindexkeys.colid = syscolumns.colid) then 1 else 0 end) AS [PK], (Case syscolumns.status when 128 then 1 else 0 end) AS [Identity] from syscolumns inner join systypes on ( syscolumns.xtype = systypes.xtype and systypes.name <>‘_default_‘ and systypes.name<>‘sysname‘) left outer join sys.extended_properties on ( sys.extended_properties.major_id=syscolumns.id and minor_id=syscolumns.colid) where syscolumns.id = (select id from sysobjects where name=‘NDS_TFileForm‘) order by syscolumns.colid
SQL Server2008中通过SQL获取表结构
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。