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:

Jeremy Kadlec is a Founder, Editor and Author at MSSQLTips.com with more than 300 contributions and 25+ years of SQL Server experience. Jeremy leads a team of more than 300 authors helping millions of SQL Server professionals around the globe every second of the day for the last 20 years. He is also the CTO @ Edgewood Solutions and a six-time SQL Server MVP based on his community contributions. Jeremy brings 25+ years of SQL Server DBA and Developer knowledge to the community and holds a bachelor’s degree from SSU and master’s degree from UMBC.

