澳门网络娱乐游戏平台-澳门电子游戏娱乐网址-官方直营

澳门电玩城娱乐app生成数据字典

 

 

--数据库表名及字段名都无数据字典,今后补给上。

 

 

DECLARE @TableName NVARCHAR(35) ,

--暂且想到如下笨办法:

@htmls VARCHAR(8000)

--思路,分两步,一是填写表的字典。二是填写表中字段的字典。

DECLARE @字段名称 VARCHA哈弗(200卡塔尔国

--将表名导出到Table_Description

DECLARE @类型 VARCHAR(200)

--将列名导出到Column_Description

DECLARE @长度 VARCHAR(200)

--然后填写上Description,最终调用存款和储蓄进程,分别更新或增多字典到表和字段上。

DECLARE @数值精度 VARCHA冠道(200卡塔尔(英语:State of Qatar)

--最后,利用三视图,显示数据字典:表构造,索引,全部客商对象。表结果是首要。

DECLARE @小数位数 VARCHALAND(200卡塔尔(قطر‎

--也得以用动软生成Word或Html情势。

DECLARE @默认值 VARCHAR(200)

 

DECLARE @允许为空 VARCHA大切诺基(200卡塔尔

大器晚成、起首:导出表新闻到Table_Description表

DECLARE @外键 VARCHAR(200)

创建Table_Description表

DECLARE @主键 VARCHAR(200)

create table Table_Description

DECLARE @描述 VARCHAR(200)

(TableName nvarchar(50),Descriptions nvarchar(255),RowCounts int,IsUsed bit)  

 

载入客商表到Table_Description表

SET NOCOUNT ON;

insert into Table_Description (TableName)

 

select name from sys.tables a where name not in ('sysdiagrams','Table_Description','Column_Description')

DECLARE Tbls CURSOR

and not exists (select 1 from Table_Description where TableName=a.name)

FOR

order by name

SELECT DISTINCT

 

Table_name

总括表记录行总量代码示例:

FROM INFORMATION_SCHEMA.COLUMNS

select schema_name(t.schema_id) as [Schema], t.name as TableName,i.rows as [RowCount]

ORDER BY Table_name

from sys.tables as t, sysindexes as i

OPEN Tbls

where t.object_id = i.id and i.indid <=1

PRINT '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ";'

 

PRINT '<html xmlns=";'

立异表记录行总的数量

PRINT ' <head>'

update  a set rowcounts=b.[rowcount] from Table_Description  a,

PCRUISERINT ' <title>数据库字典</title>'

(select schema_name(t.schema_id) as [Schema], t.name as TableName,i.rows as [RowCount]

PRINT ' <style type="text/css">'

from sys.tables as t, sysindexes as i

PCRUISERINT ' body{margin:0; font:11pt "arial", "微软雅黑"; cursor:default;}'

where t.object_id = i.id and i.indid <=1) b

PRINT ' .tableBox{margin:10px auto; padding:0px; width:1000px; height:auto; background:#FBF5E3; border:1px solid #45360A}'

where a.TableName=b.TableName

PRINT ' .tableBox h3 {font-size:12pt; height:30px; line-height:30px; background:#45360A; padding:0px 0px 0px 15px; color:#FFF; margin:0px; text-align:left }'

 

PRINT ' .tableBox table {width:1000px; padding:0px }'

单身填写各表的字典

PRINT ' .tableBox th {height:25px; border-top:1px solid #FFF; border-left:1px solid #FFF; background:#F7EBC8; border-right:1px solid #E0C889; border-bottom:1px solid #E0C889 }'

update Table_Description set Descriptions='客商资料表.主档',isused=1 where TableName='KFZL' 

PRINT ' .tableBox td {height:25px; padding-left:10px; border-top:1px solid #FFF; border-left:1px solid #FFF; border-right:1px solid #E0C889; border-bottom:1px solid #E0C889 }'

 

PRINT ' </style>'

去除无用资料字典表

PRINT ' </head>'

delete from Table_Description where isnull(IsUsed,0)=0

PRINT ' <body>'

 

FETCH NEXT FROM Tbls INTO @TableName

到此字典表Table_Description填写完毕,结果如下图:

WHILE @@FETCH_STATUS = 0

 

BEGIN

 澳门电玩城娱乐app 1

 

 

 

 二、载入字典表的不论什么事列到Column_Description表

IF EXISTS ( SELECT 1

载入字典表的漫天列

FROM sys.extended_properties AS A

create table Column_Description

WHERE A.major_澳门电玩城娱乐app,id = OBJECT_ID(@TableName)

(TableName nvarchar(50),ColumnName nvarchar(50),Descriptions nvarchar(255),IsUsed bit)

AND name = 'MS_Description'

insert into Column_Description (TableName,ColumnName)

AND minor_id = 0 )

select b.TableName,a.name from sys.all_columns a,Table_Description b

SELECT @htmls = ' <h3>'

where a.object_id = object_id(b.TableName) and b.IsUsed=1

  • @TableName + ' : '

    • CAST(Value AS VARCHAR(1000)) + '</h3>'

and not exists (select 1 from Column_Description c where b.TableName=c.TableName and a.name=c.ColumnName)

FROM sys.extended_properties AS A

order by b.TableName,a.column_id

WHERE A.major_id = OBJECT_ID(@TableName)

 

AND name = 'MS_Description'

 

AND minor_id = 0

导出Column_Description到Excel进行字典填写,填写完后,回传到Column_Description表中。效果图如下:

ELSE

 

SELECT @htmls = ' <h3>'

 澳门电玩城娱乐app 2

  • @TableName + '</h3>'

澳门电玩城娱乐app 3

 

 

 

三、批量增添数据表的字典描述

PRINT ' <div class="tableBox">'

 

PRINT @htmls

 

PRINT ' <table cellspacing="0">'

declare @TableName nvarchar(50),@Descriptions nvarchar(255)

PRINT ' <tr>'

 

P昂科拉INT ' <th>字段名称</th>'

declare cur cursor for

PRINT ' <th>类型</th>'

select tablename,descriptions from table_description where isnull(descriptions,'')<>'' order by tablename

PRINT ' <th>长度</th>'

open cur

PRubiconINT ' <th>数值精度</th>'

fetch next from cur into @TableName,@Descriptions

PGL450INT ' <th>小数位数</th>'

while (@@fetch_status=0)

PRINT ' <th>默认值</th>'

begin

POdysseyINT ' <th>允许为空</th>'

    IF EXISTS (select 1 from sys.extended_properties WHERE name='MS_Description' and major_id=OBJECT_ID(''+@TableName+'') and minor_id=0) 

PRINT ' <th>外键</th>'

    begin

PRINT ' <th>主键</th>'

        EXEC sp_updateextendedproperty N'MS_Description',@Descriptions,N'SCHEMA',N'dbo',N'TABLE',@TableName

PRINT ' <th>描述</th>'

    end

PRINT ' </tr>'

    else

 

    begin

DECLARE TRows CURSOR

        EXEC sp_addextendedproperty N'MS_Description',@Descriptions,N'SCHEMA',N'dbo',N'TABLE',@TableName 

FOR

    end

SELECT ' <td>'

    

  • CAST(clmns.name AS VARCHAR(35)) + '</td>' ,

    ' <td>'

  • CAST(udt.name AS CHAR(15)) + '</td>' ,

    ' <td>'

  • CAST(CAST(CASE WHEN typ.name IN ( N'nchar',

    print '数据表['+@TableName+']描述['+@Descriptions+']累积成功!'

N'nvarchar' )

 

AND clmns.max_length <> -1

    fetch next from cur into @TableName,@Descriptions

THEN clmns.max_length / 2

end

ELSE clmns.max_length

close cur

END AS INT) AS VARCHAR(20)) + '</td>' ,

deallocate cur

' <td>'

 

  • CAST(CAST(clmns.precision AS INT) AS VARCHAR(20))

  • '</td>' ,

    ' <td>'

  • CAST(CAST(clmns.scale AS INT) AS VARCHAR(20))

  • '</td>' ,

    ' <td>'

  • ISNULL(CAST(cnstr.definition AS VARCHAR(20)), '')

 

  • '</td>' ,

    ' <td>'

  • CAST(clmns.is_nullable AS VARCHAR(20)) + '</td>' ,

    ' <td>'

  • CAST(clmns.is_computed AS VARCHAR(20)) + '</td>' ,

    ' <td>'

  • CAST(clmns.is_identity AS VARCHAR(20)) + '</td>' ,

    ' <td>'

  • ISNULL(CAST(exprop.value AS VARCHAR(500)), '')

四、批量增进数据字段的字典描述

  • '</td>'

 

FROM sys.tables AS tbl

 

INNER JOIN sys.all_columns AS clmns ON clmns.object_id = tbl.object_id

declare @TableName nvarchar(50),@ColumnName nvarchar(50),@Descriptions nvarchar(255)

LEFT OUTER JOIN sys.indexes AS idx ON idx.object_id = clmns.object_id

 

AND 1 = idx.is_primary_key

declare cur cursor for

LEFT OUTER JOIN sys.index_columns AS idxcol ON idxcol.index_id = idx.index_id

select tablename,columnname,descriptions from column_description where isnull(descriptions,'')<>'' order by tablename,columnname

AND idxcol.column_id = clmns.column_id

open cur

AND idxcol.object_id = clmns.object_id

fetch next from cur into @TableName,@ColumnName,@Descriptions

AND 0 = idxcol.is_included_column

while (@@fetch_status=0)

LEFT OUTER JOIN sys.types AS udt ON udt.user_type_id = clmns.user_type_id

begin

LEFT OUTER JOIN sys.types AS typ ON typ.user_type_id = clmns.system_type_id

    IF EXISTS (select 1 from sys.extended_properties WHERE name='MS_Description' and major_id=OBJECT_ID(''+@TableName+'') 

AND typ.user_type_id = typ.system_type_id

    and minor_id in (select colid from syscolumns where id=object_id(''+@TableName+'') and name=''+@ColumnName+'') )

LEFT JOIN sys.default_constraints AS cnstr ON cnstr.object_id = clmns.default_object_id

    begin

LEFT OUTER JOIN sys.extended_properties exprop ON exprop.major_id = clmns.object_id

        EXEC sp_updateextendedproperty N'MS_Description',@Descriptions,N'SCHEMA',N'dbo',N'TABLE',@TableName,N'COLUMN',@ColumnName

AND exprop.minor_id = clmns.column_id

    end

AND exprop.name = 'MS_Description'

    else

WHERE ( tbl.name = @TableName

    begin

AND exprop.class = 1

        EXEC sp_addextendedproperty N'MS_Description',@Descriptions,N'SCHEMA',N'dbo',N'TABLE',@TableName,N'COLUMN',@ColumnName

) --I don't wand to include comments on indexes

    end

ORDER BY clmns.column_id ASC

    

OPEN TRows

    print '数据表['+@TableName+']字段['+@ColumnName+']描述['+@Descriptions+']加上成功!'

FETCH NEXT FROM TRows INTO @字段名称, @类型, @长度, @数值精度, @小数位数, @暗许值,

 

@允许为空, @外键, @主键, @描述

    fetch next from cur into @TableName,@ColumnName,@Descriptions

WHILE @@FETCH_STATUS = 0

end

BEGIN

close cur

PRINT ' <tr>'

deallocate cur

P本田CR-VINT @字段名称

 

PRINT @类型

 

PRINT @长度

 

P福睿斯INT @数值精度

五、利用视图展现数据字典

POdysseyINT @小数位数

 

PRINT @默认值

 

P凯雷德INT @允许为空

Set nocount on  

PRINT @外键

DECLARE @TableName nvarchar(35)  

PRINT @主键

DECLARE Tbls CURSOR  

PRINT @描述

FOR  

PRINT ' </tr>'

本文由澳门网络娱乐游戏平台发布于数据库,转载请注明出处:澳门电玩城娱乐app生成数据字典

相关阅读