Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help creating a Data Dictionary

Status
Not open for further replies.

codemech

Programmer
Feb 8, 2004
34
US
I use the following query to create a data dictionary which returns the table name, column name, data type, field length and nullable option. I can't seem to figure out how to indicate if a field is set as a primary key. Note: The LIKE statement just return my (M)ain and
(L)ookup tables.

SELECT TOP 100 PERCENT o.name AS
, c.name AS [Column], t.name AS Type, c.length, c.isnullable
FROM dbo.sysobjects o
INNER JOIN dbo.syscolumns c ON o.id = c.id
INNER JOIN dbo.systypes t ON c.xtype = t.xtype
WHERE (o.name LIKE N'm_%') OR
(o.name LIKE N'l_%')
ORDER BY o.name, c.name

Thanks,
C
 
Try using INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
instead of system tables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top