Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Data Dictionary Compilation Issues

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-10-23 : 07:40:38
Stuart writes "Hello,

Please can you help. I am compiling a data dictionary of our corporate databases and I have run the following query to get the majority of information I need:

select table_name, column_name, ordinal_position,
is_nullable, data_type, character_maximum_length
FROM INFORMATION_SCHEMA.columns
order by table_name

however there are two things missing from this information:

1. No primary keys are displayed. Please can you advise me of a query I can run which shows me the primary keys of all the tables in a database (approx 500 tables per database), saving me having to go into each table in town and make a note of the primary key. Unfortunately even if the "is_nullable" value is no it doesn't correspond to each table's primary key.

2. The character_maximum_length field only seems to display the correct value of fields with data type varchar. decimal, money, int, bigint and datetime return NULL, whereas text returns 2147483647. How can I return the correct values for all data types?

I would really appreciate your help on this as it will save me several days of manual data entry.

Thanks very much,

Stuart"

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-10-23 : 08:43:08
i use this when i make a data dictionary

SELECT distinct C.ORDINAL_POSITION, C.COLUMN_NAME AS [Column],
C.IS_NULLABLE AS [Allows Nulls?], C.DATA_TYPE AS [Type], e.value AS column_description, sc.length
, cc.constraint_name,
case when tc.constraint_name like 'FK_%' then replace(tc.constraint_name, 'FK_' + tc.table_name + '_', '') else NULL end as fktarget
FROM
INFORMATION_SCHEMA.Tables T JOIN INFORMATION_SCHEMA.Columns C
ON T.TABLE_NAME = C.TABLE_NAME
full outer join
(syscolumns sc inner join sysobjects so on sc.id = so.id)
on sc.name = c.column_name
full OUTER JOIN
::fn_listextendedproperty(N'MS_Description', N'user', N'dbo', N'table', @name, N'column', NULL) e
ON sc.name = e.objname
full outer join
information_schema.constraint_column_usage cc
on cc.column_name = e.objname and cc.table_name = @name
full outer join
information_schema.table_constraints tc
on cc.constraint_name = tc.constraint_name
WHERE
T.TABLE_NAME = @name and
so.name = @name
and ((tc.constraint_name not like 'CK%') or (tc.constraint_name is null))
ORDER BY C.ORDINAL_POSITION
where @name = table name
simple enough to loop through all your talbes. same for databases i guess.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2006-10-28 : 11:17:02
You might also check out SqlSpec, an app I wrote that
generates very comprehensive data dictionaries, for 2000 and 2005,
and Analysis Server 2005 too. SqlSpec is my hobby.

Link to it is in my sig below.


SqlSpec - a fast, cheap, and comprehensive data dictionary generator for
SQL Server 2000/2005 and Analysis Server 2005 - http://www.elsasoft.org
Go to Top of Page
   

- Advertisement -