SQLUSA.com
SQL SERVER 2008 GRAND SLAM
FREE TRIAL  CLICK HERE TO ORDER  SEARCH
SQL JOBS SQL Server Training Scripts JOB BANK
  SQL Server 2008 Training Scripts  
  SQL Server 2005 Training Scripts  
News SQL Server Articles SQL Format

How to list all database objects with definition?

Execute the following Microsoft SQL Server T-SQL database administration script to list the definition of database objects:

USE AdventureWorks;

 

SELECT   DISTINCT o.name AS [Object Name],

                  CASE

                    WHEN o.xtype = 'C' THEN 'CHECK constraint'

                    WHEN o.xtype = 'D' THEN 'Default or DEFAULT constraint'

                    WHEN o.xtype = 'F' THEN 'FOREIGN KEY constraint'

                    WHEN o.xtype = 'L' THEN 'Log'

                    WHEN o.xtype = 'FN' THEN 'Scalar function'

                    WHEN o.xtype = 'IF' THEN 'In-line table-function'

                    WHEN o.xtype = 'P' THEN 'Stored procedure'

                    WHEN o.xtype = 'PK' THEN 'PRIMARY KEY constraint (type is K)'

                    WHEN o.xtype = 'RF' THEN 'Replication filter stored procedure'

                    WHEN o.xtype = 'TF' THEN 'Table function'

                    WHEN o.xtype = 'TR' THEN 'Trigger'

                    WHEN o.xtype = 'UQ' THEN 'UNIQUE constraint (type is K)'

                    WHEN o.xtype = 'V' THEN 'View'

                    WHEN o.xtype = 'X' THEN 'Extended stored procedure'

                    ELSE NULL

                  END AS [Object Type],

                  o.id   AS ObjectID,

                  TEXT   AS Definition

FROM     sysobjects o

         JOIN syscomments c

           ON o.id = c.id

WHERE    o.category = 0

   AND   o.xtype not in ('U','S')

ORDER BY [Object Type],

         [Object Name];

/* Object Name    Object Type ObjectID    Definition

CK_BillOfMaterials_BOMLevel   CHECK constraint  309576141   ([ProductAssemblyID] IS NULL AND [BOMLevel]=(0) AND [PerAssemblyQty]=(1.00) OR [ProductAssemblyID] IS NOT NULL AND [BOMLevel]>=(1))

CK_BillOfMaterials_EndDate    CHECK constraint  277576027   ([EndDate]>[StartDate] OR [EndDate] IS NULL)

CK_BillOfMaterials_PerAssemblyQty   CHECK constraint  325576198   ([PerAssemblyQty]>=(1.00))

*/

 

Related article:

http://www.sqlusa.com/bestpractices2008/objectdefinition/

 

Order SQL 2008 GRAND SLAM Today!
SQLUSA.com Home Page
SQL Server Training at www.sqlusa.com.
SQL Server 2008 Video Training at www.sqlusa.com.
SQL Server 2005 Training Videos at www.sqlusa.com.
Microsoft SQL Server 2000 Training Videos at www.sqlusa.com.

FREE SQL & Business Intelligence / OLAP Short Videos on YOUTUBE.com

Microsoft Community Contributor 2011
Invest in Your SUCCESS!

Search SQLUSA FREE SQL Server Articles & FREE T-SQL Scripts


Copyright 2005-2011, SMI Corp. All Rights Reserved.

SQL Server 2012 is a program product of Microsoft Corporation.
SQL Server 2008 is a program product of Microsoft Corporation.
SQL Server 2005 is a program product of Microsoft Corporation.
SQL Server 2000 is a program product of Microsoft Corporation.