SQLServer2008/2005 生成資料字典SQL語句
以前用那個SQL語句來生成那個SQLServer庫的資料字典,在SQL2000下用的挺好的,最近裝上了那個SQL2008來研究,
突然發現不能在2008下用了,查了查資料,發現2008下有一些改動
貼上來留個記號
SQLServer2008/2005 生成資料字典語句
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->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='要查詢的表' --如果只查詢指定表,加上此條件
order by a.id,a.colorder
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->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='要查詢的表' --如果只查詢指定表,加上此條件
order by a.id,a.colorder
以前的SQL2000下的語句
就改動了個sysproperties
Code
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->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 sysproperties g on a.id=g.id and a.colid=g.smallid
left join sysproperties f on d.id=f.id and f.smallid=0
--where d.name='要查詢的表' --如果只查詢指定表,加上此條件
order by a.id,a.colorder
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->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 sysproperties g on a.id=g.id and a.colid=g.smallid
left join sysproperties f on d.id=f.id and f.smallid=0
--where d.name='要查詢的表' --如果只查詢指定表,加上此條件
order by a.id,a.colorder
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16436858/viewspace-594319/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Java中如何解析SQL語句、格式化SQL語句、生成SQL語句?JavaSQL
- 【資料庫】SQL語句資料庫SQL
- 1.4 資料庫和常用SQL語句(正文)——MySQL資料庫命令和SQL語句資料庫MySql
- 資料庫常用的sql語句大全--sql資料庫SQL
- 資料庫常用操作SQL語句資料庫SQL
- jsqlparser使用記錄---生成sql語句JSSQL
- sql server 2005資料庫快照SQLServer資料庫
- mysql資料庫語句自動生成MySql資料庫
- 定時生成分月表sql語句SQL
- sql 正則替換資料庫語句!SQL資料庫
- 資料庫常用的sql語句彙總資料庫SQL
- GaussDB資料庫SQL系列-動態語句資料庫SQL
- MYSQL---SQL語句的資料快取MySql快取
- navicat生成mysql資料字典MySql
- excel表結構生成powerDesigner模型,生成建表語句sqlExcel模型SQL
- 使用sql語句查詢平均值,使用sql語句查詢資料總條數, not in 篩選語句的使用SQL
- SQL語句SQL
- 複製表結構和資料SQL語句SQL
- Oracle資料庫SQL語句執行過程Oracle資料庫SQL
- mysql資料庫sql語句基礎知識MySql資料庫
- MySQL資料庫中SQL語句分幾類?MySql資料庫
- MySQL資料庫:7、SQL常用查詢語句MySql資料庫
- mysql使用phpmyadmin批次替換資料sql語句MySqlPHP
- EFCore常規操作生成的SQL語句一覽SQL
- lavavel 自動生成資料字典
- sql server 2005 資料修改的內部原理SQLServer
- Sql Server 資料庫獲取字串中小寫字母的SQL語句SQLServer資料庫字串
- SQL Server 資料庫部分常用語句小結(二)SQLServer資料庫
- Oracle OCP(01):使用SQL SELECT語句檢索資料OracleSQL
- SQL server資料庫表碎片比例查詢語句SQLServer資料庫
- SQL Server 資料庫部分常用語句小結(一)SQLServer資料庫
- idea內建資料庫 + sql語句庫表操作Idea資料庫SQL
- 【SQL】9 SQL INSERT INTO 語句SQL
- 【SQL】10 SQL UPDATE 語句SQL
- 【SQL】11 SQL DELETE 語句SQLdelete
- 自定義註解例項實現SQL語句生成SQL
- SQL SELECT 語句SQL
- sql常用語句SQL
- 如何建立和還原SQL Server 2005資料庫?SQLServer資料庫