您好,登錄后才能下訂單哦!
引用自《SQL Server 2012 Internals》
“
As views, these metadata objects are based on an underlying Transact-SQL (T-SQL) defnition. The most straightforward way to see the defnition of these views is by using the object_defnition function. (You can also see the defnition of these system views by using sp_helptext or by selecting from the catalog view sys.system_sql_modules.) So to see the defnition of sys.tables, you can execute the following:
SELECT object_definition (object_id('sys.tables'));
”
方法一:
OBJECT_DEFINITION
返回指定對(duì)象的定義的 Transact-SQL 源文本。
SELECT object_definition (object_id('sys.tables'));
https://msdn.microsoft.com/zh-cn/library/ms176090.aspx
方法二:
sp_helptext
顯示用戶定義規(guī)則的定義、默認(rèn)值、未加密的 Transact-SQL 存儲(chǔ)過(guò)程、用戶定義 Transact-SQL 函數(shù)、觸發(fā)器、計(jì)算列、CHECK 約束、視圖或系統(tǒng)對(duì)象(如系統(tǒng)存儲(chǔ)過(guò)程)。
EXEC sp_helptext 'sys.tables'; GO
https://msdn.microsoft.com/zh-cn/library/ms176112.aspx
方法三:
sys.system_sql_modules
為每個(gè)包含 SQL 語(yǔ)言定義模塊的系統(tǒng)對(duì)象返回一行。 類型為 FN、IF、P、PC、TF 和 V 的系統(tǒng)對(duì)象具有關(guān)聯(lián)的 SQL 模塊。 若要標(biāo)識(shí)該包含對(duì)象,可以將該視圖聯(lián)接到 sys.system_objects。
SELECT ssm.object_id, OBJECT_NAME(ssm.object_id) AS object_name, SCHEMA_NAME(t.schema_id) AS schema_name, t.type, t.type_desc, ssm.definition FROM sys.system_sql_modules ssm INNER JOIN sys.system_objects t ON ssm.object_id = t.object_id WHERE t.type='P' GO
https://msdn.microsoft.com/zh-cn/library/ms188034.aspx
示例:
select object_name(m.object_id) as name, * from sys.system_sql_modules m inner join sys.system_objects t on m.object_id=t.object_id where type='P' and name='sp_renamedb' select object_name(m.object_id) as name, * from sys.system_sql_modules m inner join sys.system_objects t on m.object_id=t.object_id where type='V' and name='systypes'
sys.sql_modules
對(duì)每個(gè) SQL 語(yǔ)言定義的模塊對(duì)象都返回一行。類型為 P、RF、V、TR、FN、IF、TF 和 R 的對(duì)象均有關(guān)聯(lián)的 SQL 模塊。在此視圖中,獨(dú)立的默認(rèn)值,即 D 類型的對(duì)象也具有 SQL 模塊定義。有關(guān)這些類型的說(shuō)明,請(qǐng)參閱 sys.objects 目錄視圖中的類型列。
SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS object_name, SCHEMA_NAME(o.schema_id) AS schema_name, o.type, o.type_desc, sm.definition FROM sys.sql_modules AS sm INNER JOIN sys.objects AS o ON sm.object_id = o.object_id ORDER BY o.type; GO
https://technet.microsoft.com/zh-cn/library/ms175081.aspx
示例:
SELECT OBJECT_NAME(object_id) FROM sys.sql_modules WHERE OBJECTPROPERTY(object_id, 'IsProcedure') = 1 AND definition LIKE '%yourText%'
sys.all_sql_modules
返回 sys.sql_modules 和 sys.system_sql_modules 的聯(lián)合。
https://msdn.microsoft.com/zh-cn/library/ms184389.aspx
方法四:
INFORMATION_SCHEMA
信息架構(gòu)視圖是 SQL Server 提供的幾種獲取元數(shù)據(jù)的方法之一。 信息架構(gòu)視圖提供獨(dú)立于系統(tǒng)表的內(nèi)部 SQL Server 元數(shù)據(jù)視圖。 盡管已經(jīng)對(duì)基礎(chǔ)系統(tǒng)表進(jìn)行了重要的修改,信息架構(gòu)視圖仍然可使應(yīng)用程序正常工作。 SQL Server 中包含的信息架構(gòu)視圖符合 ISO 標(biāo)準(zhǔn)中的信息架構(gòu)定義。
在引用當(dāng)前服務(wù)器時(shí),SQL Server 支持三部分命名約定。 ISO 標(biāo)準(zhǔn)也支持三部分命名約定。 但是,兩種命名約定中使用的名稱并不相同。 信息架構(gòu)視圖是在名為 INFORMATION_SCHEMA 的特殊架構(gòu)中定義的。 此架構(gòu)包含在每個(gè)數(shù)據(jù)庫(kù)中。 每個(gè)信息架構(gòu)視圖包含特定數(shù)據(jù)庫(kù)中存儲(chǔ)的所有數(shù)據(jù)對(duì)象的元數(shù)據(jù)。
下表顯示了 SQL Server 名稱和 SQL 標(biāo)準(zhǔn)名稱之間的關(guān)系。
SQL Server 名稱 | 對(duì)應(yīng)的 SQL 標(biāo)準(zhǔn)等價(jià)名稱 |
數(shù)據(jù)庫(kù) | 目錄 |
架構(gòu) | 架構(gòu) |
Object | Object |
用戶定義數(shù)據(jù)類型 | 域 |
引用信息架構(gòu)視圖時(shí),必須使用包含 INFORMATION_SCHEMA 架構(gòu)名稱的限定名。
SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLUMN_DEFAULT FROM AdventureWorks2014.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = N'Product'; GO
https://msdn.microsoft.com/zh-cn/library/ms186778.aspx
INFORMATION_SCHEMA.ROUTINES
為當(dāng)前數(shù)據(jù)庫(kù)中可由當(dāng)前用戶訪問(wèn)的每個(gè)存儲(chǔ)過(guò)程及函數(shù)返回一行。 描述返回值的列只適用于函數(shù)。 對(duì)于存儲(chǔ)過(guò)程,這些列將為 NULL。
若要從這些視圖中檢索信息,請(qǐng)指定 INFORMATION_SCHEMA.view_name 的完全限定名稱。
ROUTINE_DEFINITION
nvarchar(4000)
列包含創(chuàng)建函數(shù)或存儲(chǔ)過(guò)程的源語(yǔ)句。 這些源語(yǔ)句有可能包含嵌入式回車符。 如果將此列返回給某個(gè)以文本格式顯示結(jié)果的應(yīng)用程序,則 ROUTINE_DEFINITION 結(jié)果中的嵌入式回車符可能會(huì)影響整個(gè)結(jié)果集的格式。 如果選擇 ROUTINE_DEFINITION 列,則必須對(duì)嵌入式回車符進(jìn)行調(diào)整,例如,可將結(jié)果集返回到一個(gè)網(wǎng)格中或者將 ROUTINE_DEFINITION 返回到其自己的文本框中。
如果函數(shù)或存儲(chǔ)過(guò)程未加密,返回函數(shù)或存儲(chǔ)過(guò)程的定義文本最前面的 4000 字符。 否則,返回 NULL。
若要確保獲得完整定義,請(qǐng)查詢 OBJECT_DEFINITION 函數(shù)或 sys.sql_modules 目錄視圖中的 definition 列。
SELECT SPECIFIC_CATALOG,SPECIFIC_SCHEMA,SPECIFIC_NAME,ROUTINE_TYPE FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_DEFINITION LIKE '%yourText%';
https://msdn.microsoft.com/zh-cn/library/ms188757.aspx
引用自《SQL Server 2012 Internals》
“
Information schema views
Information schema views, introduced in SQL Server 7.0, were the original system table-independent view of the SQL Server metadata. The information schema views included in SQL Server 2012 comply with the SQL-92 standard, and all these views are in a schema called INFORMATION_SCHEMA. Some information available through the catalog views is available through the information schema views, and if you need to write a portable application that accesses the metadata, you should consider using these objects. However, the information schema views show only objects compatible with the SQL-92 standard. This means no information schema view exists for certain features, such as indexes, which aren’t defned in the standard. (Indexes are an implementation detail.) If your code doesn’t need to
be strictly portable, or if you need metadata about nonstandard features such as indexes, flegroups, the CLR, and SQL Server Service Broker, using the Microsoft-supplied catalog views is suggested. Most examples in the documentation, as well as in this and other reference books, are based on the catalog view interface.
”
MySQL中的 INFORMATION_SCHEMA Tables
INFORMATION_SCHEMA
provides access to database metadata, information about the MySQL server such as the name of a database or table, the data type of a column, or access privileges. Other terms that are sometimes used for this information are data dictionary and system catalog.
http://dev.mysql.com/doc/refman/5.7/en/information-schema.html
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。