SQL Server 2005で、テーブル定義らしいものを取得するクエリです。
これを使って、テーブル定義書を自動生成させてます。
- select
- Col.name as '名称'
- ,(Select top 1 name From systypes Where systypes.xtype = Col.xtype) as '型'
- ,Col.length as '桁数'
- ,case isnull(Col.scale,0)
- when 0 then ' '
- else cast( Col.scale as char(10) )
- end '小数部'
- ,case Col.isnullable
- when 0 then '○'
- else ' '
- end 'NN'
- ,isnull((select case colid when 0 then '' else '○' end from sysindexkeys as keys where col.id = keys.id and col.colid = keys.colid and keys.indid = 1),' ') as 'PK'
- ,isnull((select top 1 ex.value from sys.extended_properties as ex where col.id = ex.major_id and ex.minor_id = col.colid and ex.name = 'MS_Description' ),' ') as 'コメント'
- From syscolumns as col
- inner join sysobjects as obj on col.id = obj.id
- Where obj.name = '<テーブル名>'
select
Col.name as '名称'
,(Select top 1 name From systypes Where systypes.xtype = Col.xtype) as '型'
,Col.length as '桁数'
,case isnull(Col.scale,0)
when 0 then ' '
else cast( Col.scale as char(10) )
end '小数部'
,case Col.isnullable
when 0 then '○'
else ' '
end 'NN'
,isnull((select case colid when 0 then '' else '○' end from sysindexkeys as keys where col.id = keys.id and col.colid = keys.colid and keys.indid = 1),' ') as 'PK'
,isnull((select top 1 ex.value from sys.extended_properties as ex where col.id = ex.major_id and ex.minor_id = col.colid and ex.name = 'MS_Description' ),' ') as 'コメント'
From syscolumns as col
inner join sysobjects as obj on col.id = obj.id
Where obj.name = '<テーブル名>'
2 件のコメント:
参考になりました~
非常に参考になりました!
ありがとうございます。
コメントを投稿