SQLServer導出數據庫字典的詳細圖文教程
SQL
直接修改帶注釋那行的表名稱即可。
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 COLUMNPROPERTY(a.id,a.name,"IsIdentity")=1 then "√"else "" end, 主鍵=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 = a.id AND colid=a.colid ))) then "√" else "" end, 類型=b.name, 占用字節數=a.length, 長度=COLUMNPROPERTY(a.id,a.name,"PRECISION"), 小數位數=isnull(COLUMNPROPERTY(a.id,a.name,"Scale"),0), 允許空=case when a.isnullable=1 then "√"else "" end, 默認值=isnull(e.text,""), 字段說明=isnull(g.[value],"") FROM syscolumns a left join systypes b on a.xtype=b.xusertype inner join sysobjects d on a.id=d.id and d.xtype="U" and d.name<>"dtproperties" left join syscomments e on a.cdefault=e.id left join sys.extended_properties g on a.id=g.major_id and a.colid=g.minor_id left join sys.extended_properties f on d.id=f.major_id and f.minor_id =0 where d.name="girlSix" --如果只查詢指定表,加上此條件 order by a.id,a.colorder
測試sql
CREATE TABLE [dbo].[girlSix] ([id] varchar(32) NOT NULL DEFAULT (replace(newid(),"-","")) ,[createDate] datetime NOT NULL DEFAULT (getdate()) ,[nickName] varchar(30) NOT NULL ,[introduce] nvarchar(200) NOT NULL ) GOIF ((SELECT COUNT(*) from fn_listextendedproperty("MS_Description", "SCHEMA", N"dbo", "TABLE", N"girlSix", "COLUMN", N"nickName")) > 0) EXEC sp_updateextendedproperty @name = N"MS_Description", @value = N"名字", @level0type = "SCHEMA", @level0name = N"dbo", @level1type = "TABLE", @level1name = N"girlSix", @level2type = "COLUMN", @level2name = N"nickName"ELSEEXEC sp_addextendedproperty @name = N"MS_Description", @value = N"名字", @level0type = "SCHEMA", @level0name = N"dbo", @level1type = "TABLE", @level1name = N"girlSix", @level2type = "COLUMN", @level2name = N"nickName"GOIF ((SELECT COUNT(*) from fn_listextendedproperty("MS_Description", "SCHEMA", N"dbo", "TABLE", N"girlSix", "COLUMN", N"introduce")) > 0) EXEC sp_updateextendedproperty @name = N"MS_Description", @value = N"介紹", @level0type = "SCHEMA", @level0name = N"dbo", @level1type = "TABLE", @level1name = N"girlSix", @level2type = "COLUMN", @level2name = N"introduce"ELSEEXEC sp_addextendedproperty @name = N"MS_Description", @value = N"介紹", @level0type = "SCHEMA", @level0name = N"dbo", @level1type = "TABLE", @level1name = N"girlSix", @level2type = "COLUMN", @level2name = N"introduce"GO -- ------------------------------ Records of girlSix-- ----------------------------INSERT INTO [dbo].[girlSix] ([id], [createDate], [nickName], [introduce]) VALUES (N"04e3d962adcb4a5b8fefaf8b46995e85", N"2020-05-27 09:05:52.000", N"董新穎", N"郭老師關門弟子之一。");GOINSERT INTO [dbo].[girlSix] ([id], [createDate], [nickName], [introduce]) VALUES (N"568fc305930347d3bec1ddd08c71ad29", N"2020-05-27 09:01:09.000", N"王笑涵", N"北方有佳人,絕世而獨立。");GOINSERT INTO [dbo].[girlSix] ([id], [createDate], [nickName], [introduce]) VALUES (N"972ec358089042e0bf24fd9efca47bde", N"2020-05-27 08:59:49.000", N"牛龍珠", N"笑若桃花三月開,清風徐徐醉顏來。");GOINSERT INTO [dbo].[girlSix] ([id], [createDate], [nickName], [introduce]) VALUES (N"BDFFC6A36A53408281EB8CA242C0E7A3", N"2020-05-27 08:42:31.000", N"閆春娜", N"珠纓旋轉星宿搖,花蔓抖擻龍蛇動。");GOINSERT INTO [dbo].[girlSix] ([id], [createDate], [nickName], [introduce]) VALUES (N"efb0ca854dac456b9d8c42d4c4b1bce0", N"2020-05-27 09:03:30.000", N"劉梓佳", N"明眸善睞,輔靨承權,瑰姿艷逸,怡靜體閑,端的是好一個花王,富貴的牡丹。");GOINSERT INTO [dbo].[girlSix] ([id], [createDate], [nickName], [introduce]) VALUES (N"f839343b980e45caafaa9d2c9797294b", N"2020-05-27 09:04:53.000", N"魏慧娟", N"脈脈眼中波,盈盈花盛處。");GO -- ------------------------------ Indexes structure for table girlSix-- ---------------------------- -- ------------------------------ Primary Key structure for table [dbo].[girlSix]-- ----------------------------ALTER TABLE [dbo].[girlSix] ADD PRIMARY KEY ([id])GO
執行效果
導出結果:
點擊導出向導后會出現以下提示,我們選擇【Excel文件(2007或以上版本)(*.xlsx)】格式進行導出,單選選擇后點擊下一步。
這里的樣式提示只有鼠標放在上面的時候才會提示,這個是導出文件的放置位置,我們直接點擊【...】設置存儲位置即可。
選擇位置,我這里就放在桌面了,名字給一個就行,可以看到對應的保存格式是Excel2007的表格格式,我這個版本比較老的工具,可以使用最新的能導出更新的一些版本格式。
看到對應的路徑輸入成功,我們直接點擊下一步即可。
這里勾選一下【包含列的標題】,再點擊【下一步】。
點擊開始
完成后點擊關閉即可。
我們到桌面看看是否存在。
查看效果:
可以看到除字段說明外都是正常的,我們字段說明的時候可以采用中文,因為導出數據無論是【GBK】還是【UTF-8】都無法正常輸出中文,我們就不用麻煩了,需要使用的話可以自己處理一下最后一列的字段說明。
這里我介紹一下【Chinese_PRC_CI_AS】,因為我們創建數據庫默認的數據庫編碼格式就是這個。
指UNICODE字符集,Chinese_PRC_指針對中國簡體字UNICODE的排序規則。
雖然是中文的編碼格式,但是導出依然有問題。
期待以后都通用中文編碼格式,免得各種格式錯誤。
總結
到此這篇關于SQLServer導出數據庫字典的文章就介紹到這了,更多相關SQLServer導出數據庫字典內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!
