Returns a row for each object that is an SQL language-defined module. Objects of type P, RF, V, TR, FN, IF, TF, and R have an associated SQL module. Stand-alone defaults, objects of type D, also have an SQL module definition in this view. For a description of these types, see the type column in the sys.objects catalog view.
ID of the object of the containing object. Is unique within a database.
SQL text that defines this module.
NULL = Encrypted.
Module was created with SET ANSI_NULLS ON.
Will always be = 0 for rules and defaults.
Module was created with SET QUOTED_IDENTIFIER ON.
Module was created with SCHEMABINDING option.
1 = Schema-bound module definition depends on the default-collation of the database for correct evaluation; otherwise, 0. Such a dependency prevents changing the database's default collation.
Procedure was created WITH RECOMPILE option.
Module was declared to produce a NULL output on any NULL input.
ID of the EXECUTE AS database principal.
NULL by default or if EXECUTE AS CALLER.
ID of the specified principal if EXECUTE AS SELF or EXECUTE AS <principal>.
-2 = EXECUTE AS OWNER.
In SQL Server 2005 and later versions, the visibility of the metadata in catalog views is limited to securables that a user either owns or on which the user has been granted some permission. For more information, see Metadata Visibility Configuration.
The following example returns the name, type, and definition of each module in the AdventureWorks2008R2 database.
USE AdventureWorks2008R2; GO SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS object_name, o.type, o.type_desc, sm.definition FROM sys.sql_modules AS sm JOIN sys.objects AS o ON sm.object_id = o.object_id ORDER BY o.type; GO