By: Jeremy Kadlec | Updated: 2006-11-03 | Comments | Related: More > Database Administration
Problem
With the recent tips on data modeling (SQL Server 2005 Exposed = Data Modeling Tools and SQL Server Data Modeling Tools), a natural question that arose is: where are all of the underlying objects stored in SQL Server? As such, in this tip we will outline where the user defined objects in user defined databases for both SQL Server 2000 and 2005.
Solution
Below outlines the queries for the objects in the user databases in both SQL Server 2000 and 2005:
ID | Object Type | SQL Server 2000 | SQL Server 2005 |
1 | Data Models | Table = dtproperties
SELECT * |
Table = dbo.sysdiagrams
SELECT * |
2 | Tables | Table = sysobjects
SELECT * |
Table = sys.tables
SELECT * |
3 | Columns | Table = syscolumns
SELECT o.name, c.name |
Table = sys.all_columns
SELECT OBJECT_NAME([Object_ID]) AS 'TableName', [Name] AS 'ColumnName', Column_ID |
4 | Primary Keys | Table = sysobjects
SELECT p.name, OBJECT_NAME(parent_obj) AS 'Table Name' |
Table = sys.objects
SELECT OBJECT_NAME(o.parent_object_id) AS 'ParentObject', s.name AS 'Schema', o.Name AS 'PrimaryKey' |
5 | Foreign Keys | Table = sysforeignkeys
SELECT OBJECT_NAME(f.constid) AS 'ForeignKey', OBJECT_NAME(f.fkeyid) AS 'FKTable', c1.[name] AS 'FKColumnName', OBJECT_NAME(f.rkeyid) AS 'PKTable', c2.[name] AS 'PKColumnName' |
Table = sys.foreign_key_columns
SELECT OBJECT_NAME(f.constraint_object_id) AS 'ForeignKey', OBJECT_NAME(f.parent_object_id) AS 'FKTable', c1.[name] AS 'FKColumnName', OBJECT_NAME(f.referenced_object_id) AS 'PKTable', c2.[name] AS 'PKColumnName' |
6 | Constraints | Table = sysconstraints
SELECT o.[name] AS 'DefaultName', OBJECT_NAME(c.[id]) AS 'TableName', col.[name] AS 'ColumnName' |
Table = sys.objects
SELECT OBJECT_NAME(o.parent_object_id) AS 'ParentObject', s.name AS 'Schema', o.Name AS 'PrimaryKey' |
7 | FileGroups\Partitions | Table = sysfilegroups
SELECT * |
Table = sys.data_spaces
SELECT * |
8 | Stored Procedures | Table = sysobjects
SELECT o.[name], o.[id], o.xtype, c.[text] |
Table = sys.objects
SELECT o.[Name], o.[object_id], o.[type], m.definition |
9 | Functions | Table = sysobjects
SELECT o.[name], o.[id], o.xtype, c.[text] |
Table = sys.objects
SELECT o.[Name], o.[object_id], o.[type], m.definition |
10 | Views | Table = sysobjects
SELECT o.[name], o.[id], o.xtype, c.[text] |
Table = sys.objects
SELECT o.[Name], o.[object_id], o.[type], m.definition |
Next Steps
- When you have the need to research user defined objects, reference these tables and views listed above as the definitive source for the information.
- Consider the sample queries above as a means to begin your research and modify the queries to meet your needs.
- Next time you are asked a question or need to do some research, consider using the queries above rather than using Enterprise Manager or Management Studio. The queries will help you get a better understanding of the underlying database objects.
- For additional information about these SQL Server 2005 objects, reference these items:
- For related information on MSSQLTips.com check out these tips:
About the author
This author pledges the content of this article is based on professional experience and not AI generated.
View all my tips
Article Last Updated: 2006-11-03