【推薦】Sql Server 不常見應用之一
擷取表的基本資料、欄位列表、預存程序參數列表
——通過知識共用樹立個人品牌。
一、擷取表的基本資料
SELECT [TableName] = [Tables].name , [TableOwner] = [Schemas].name , [TableCreateDate] = [Tables].create_date , [TableModifyDate] = [Tables].modify_dateFROM sys.tables AS [Tables] INNER JOIN sys.schemas AS [Schemas] ON [Tables].schema_id = [Schemas].schema_idWHERE [Tables].name = '案卷目錄'
效果一所示:
圖一 指定表的基本資料
二、根據表名擷取欄位列表
SELECT [ColumnName] = [Columns].name , [SystemTypeName] = [Types].name , [Precision] = [Columns].precision , [Scale] = [Columns].scale , [MaxLength] = [Columns].max_length , [IsNullable] = [Columns].is_nullable , [IsRowGUIDCol] = [Columns].is_rowguidcol , [IsIdentity] = [Columns].is_identity , [IsComputed] = [Columns].is_computed , [IsXmlDocument] = [Columns].is_xml_document , [Description] = [Properties].valueFROM sys.tables AS [Tables] INNER JOIN sys.columns AS [Columns] ON [Tables].object_id = [Columns].object_id INNER JOIN sys.types AS [Types] ON [Columns].system_type_id = [Types].system_type_id AND is_user_defined = 0 AND [Types].name <> 'sysname' LEFT OUTER JOIN sys.extended_properties AS [Properties] ON [Properties].major_id = [Tables].object_id AND [Properties].minor_id = [Columns].column_id AND [Properties].name = 'MS_Description'WHERE [Tables].name =案卷目錄ORDER BY [Columns].column_id
效果二所示:
圖二 指定表的欄位列表資訊
三、擷取指定預存程序參數列表
SELECT sc.name AS 參數名 , st.name AS 類型 , sc.length AS 長度FROM syscolumns sc INNER JOIN sysobjects so ON so.id = sc.id INNER JOIN systypes st ON sc.xtype = st.xtypeWHERE so.name = 'SP_Pagination'
效果三所示:
圖三 指定預存程序的參數列表
2012 EricHu
原創作品,轉貼請註明作者和出處,留此資訊。
------------------------------------------------
cnBlobs:http://www.cnblogs.com/huyong/
CSDN: http://blog.csdn.net/chinahuyong
作者:EricHu(DB、C\S、B\S、WebService、WCF、PM等)
出處一:http://www.cnblogs.com/huyong/
出處二: http://blog.csdn.net/chinahuyong
Q Q:80368704 E-Mail: 80368704@qq.com
Q Q群:190401986
本博文歡迎大家瀏覽和轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文串連,在『參考』的文章中,我會表明參考的文章來源,尊重他人著作權。若您發現我侵犯了您的著作權,請及時與我聯絡。
更多文章請看 [置頂]索引貼——(不斷更新中)