sqlserver 生成資料字典

2022-03-04 22:42:46 字數 4304 閱讀 7038

1,

select obj.name

as 表名,

col.colorder as 序號 ,

col.name as 列名 ,

isnull(ep.[value], '') as 列說明 ,

t.name as 資料型別 ,

col.length as 長度 ,

isnull(columnproperty(col.id, col.name, 'scale'), 0) as 小數字數 ,

case when columnproperty(col.id, col.name, 'isidentity') = 1 then '√'

else ''

end as 標識 ,

case when exists ( select 1

from dbo.sysindexes si

inner join dbo.sysindexkeys sik on si.id = sik.id

and si.indid = sik.indid

inner join dbo.syscolumns sc on sc.id = sik.id

and sc.colid = sik.colid

inner join dbo.sysobjects so on so.name = si.name

and so.xtype = 'pk'

where sc.id = col.id

and sc.colid = col.colid ) then '√'

else ''

end as 主鍵 ,

case when col.isnullable = 1 then '√'

else ''

end as 允許空 ,

isnull(comm.text, '') as 預設值

from dbo.syscolumns col

left join dbo.systypes t on col.xtype = t.xusertype

inner join dbo.sysobjects obj on col.id = obj.id

and obj.xtype = 'u'

and obj.status >= 0

left join dbo.syscomments comm on col.cdefault = comm.id

left join sys.extended_properties ep on col.id = ep.major_id

and col.colid = ep.minor_id

and ep.name = 'ms_description'

left join sys.extended_properties eptwo on obj.id = eptwo.major_id

and eptwo.minor_id = 0

and eptwo.name = 'ms_description'

--where obj.name = 'scene_project_product_station_product_check_detail_extend'--表名

order by obj.name ;

2,select

sysobjects.name as 表名稱 ,

syscolumns.name as 欄位名稱 ,

systypes.name as 字段型別 ,

syscolumns.length as 字段長度 ,

isnull(columnproperty(syscolumns.id, syscolumns.name,'scale'), 0) as 小數字數 ,

case when syscolumns.isnullable=0

then ''

else ' √ '

end as 是否為空 ,

case when syscomments.text is null

then '' else syscomments.text

end as 預設值 ,

case when columnproperty(syscolumns.id, syscolumns.name, 'isidentity')= 1

then ' √ ' else ''

end as 遞增字段 ,

case when sysindexes.name is null

then ''

else sysindexes.name

end as 索引名稱 ,

case when sysindexkeys.keyno is null

then ''

else convert(varchar(10),sysindexkeys.keyno )

end as 索引位置 ,

case when sysindexes.indid=1

then ' 聚集索引 '

when sysindexes.indid>1 and sysindexes.indid<>255

then ' 非聚集索引 '

when sysindexes.indid is null

then ''

else

' 其他 '

end as 索引型別 ,

case when exists

(select 1

from sysobjects

where xtype = 'pk' and name in

(select name

from sysindexes

where indid in

(select indid

from sysindexkeys

where id = syscolumns.id and colid = syscolumns.colid)))

then ' √ ' else ''

end as 主鍵 ,

case when sysforeignkeys.constid is null

then ''

else ' √ '

end as 外健

from syscolumns -- 資料表字段

inner join sysobjects -- 資料物件

on sysobjects.id = syscolumns.id

inner join systypes -- 資料型別

on syscolumns.xtype = systypes.xtype

left outer join sys.extended_properties properties -- 字段屬性資訊

on syscolumns.id = properties.major_id

and syscolumns.colid = properties.minor_id

left outer join sys.extended_properties sysproperties -- 表屬性資訊

on sysobjects.id = sysproperties.major_id

and sysproperties.minor_id = 0

left outer join syscomments -- 注釋資訊

on syscolumns.cdefault = syscomments.id

left outer join sysindexkeys -- 索引中的鍵或列的資訊

on sysindexkeys.id = syscolumns.id

and sysindexkeys.colid = syscolumns.colid

left outer join sysindexes -- 資料庫 索引表

on sysindexes.id = sysindexkeys.id

and sysindexes.indid = sysindexkeys.indid

left outer join sysforeignkeys

on sysforeignkeys.fkeyid = syscolumns.id

and sysforeignkeys.fkey = syscolumns.colid

where (sysobjects.xtype = 'u')

order by sysobjects.id,syscolumns.colid

SqlServer生成資料字典語句

select 表名 case when a.colorder 1 then d.name else end,表說明 case when a.colorder 1 then isnull f.value,else end,字段序號 a.colorder,欄位名 a.name,標識 case when ...

SqlServer生成資料字典Excel

select 表名 case when a.colorder 1then d.name else end 表說明 case when a.colorder 1then isnull f.value,else end 字段序號 a.colorder,欄位名 a.name,字段說明 isnull g.v...

sql Server 2012 生成資料字典

select 表名 case when a.colorder 1 then d.name else end,表說明 case when a.colorder 1 then isnull f.value,else end,字段序號 a.colorder,欄位名 a.name,標識 case when ...