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 |
No comments:
Post a Comment