Here’s a quick example on how to generate a data dictionary for your sql server database.
create table #dd ( table_id int NULL, table_name nvarchar(128) NULL, column_order int NULL, column_name varchar(60) NULL, column_datatype varchar(20) NULL, column_length int NULL, column_description varchar(500) NULL)
DECLARE @table_name nvarchar(128)
DECLARE tablenames_cursor CURSOR FOR SELECT name FROM sysobjects where type = 'U' and status > 1 order by name
OPEN tablenames_cursorFETCH NEXT FROM tablenames_cursor INTO @table_nameWHILE @@FETCH_STATUS = 0BEGIN insert #dd select o.[id] as 'table_id', o.[name] as 'table_name', 0 as 'column_order', NULL as 'column_name', NULL as 'column_datatype', NULL as 'column_length', Cast(e.value as varchar(500)) as 'column_description' from sysobjects o left join ::FN_LISTEXTENDEDPROPERTY(N'MS_Description', N'user',N'dbo',N'table', @table_name, null, default) e on o.name = e.objname where o.name = @table_name
insert #dd select o.[id] as 'table_id', o.[name] as 'table_name', c.colorder as 'column_order', c.[name] as 'column_name', t.[name] as 'column_datatype', c.[length] as 'column_length', Cast(e.value as varchar(500)) as 'column_description' from sysobjects o inner join syscolumns c on o.id = c.id inner join systypes t on c.xtype = t.xtype left join ::FN_LISTEXTENDEDPROPERTY(N'MS_Description', N'user',N'dbo',N'table', @table_name, N'column', null) e on c.name = e.objname where o.name = @table_name order by c.colorder
FETCH NEXT FROM tablenames_cursor INTO @table_nameEND
CLOSE tablenames_cursorDEALLOCATE tablenames_cursor
select * from #dddrop table #dd
ReturnGo
Currently listening to: Stellar - Incubus
How we can generate the data dictionary (sql script) with column description??
I modified Oskars script for sql 2005
/*
Oskar Austegard
Here it is as a function returning a table (useful for queries like this:
select *
from dbo.fnDataDictionary()
where column_description is null
SQL 2005 changes
1) Add collate twice
COLLATE Latin1_General_CI_AS
2) used sys.objects not sysobjects
3) Removed status = 1 since
status is 0 in 2005 system view sysobjects
status is not in sys.objects
*/
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
CREATE FUNCTION fnDataDictionary ()
RETURNS @DataDictionary TABLE (
table_id int NULL,
table_name nvarchar(128) NULL,
column_order int NULL,
column_name varchar(60) NULL,
column_datatype varchar(20) NULL,
column_length int NULL,
column_description varchar(500) NULL
)
AS
BEGIN
DECLARE tablenames_cursor CURSOR FOR
SELECT name FROM sys.objects where type = 'U' order by name
OPEN tablenames_cursor
FETCH NEXT FROM tablenames_cursor INTO @table_name
WHILE @@FETCH_STATUS = 0
insert @DataDictionary
select
o.[id] as 'table_id',
o.[name] as 'table_name',
0 as 'column_order',
NULL as 'column_name',
NULL as 'column_datatype',
NULL as 'column_length',
Cast(e.value as varchar(500)) as 'column_description'
from sysobjects o
left join ::FN_LISTEXTENDEDPROPERTY(N'MS_Description', N'user',N'dbo',N'table', @table_name, null, default) e
on o.name = e.objname
where o.name = @table_name
c.colorder as 'column_order',
c.[name] as 'column_name',
t.[name] as 'column_datatype',
c.[length] as 'column_length',
from sysobjects o inner join syscolumns c on o.id = c.id inner join systypes t on c.xtype = t.xtype
left join ::FN_LISTEXTENDEDPROPERTY(N'MS_Description', N'user',N'dbo',N'table', @table_name, N'column', null) e
on c.name = e.objname
order by c.colorder
END
CLOSE tablenames_cursor
DEALLOCATE tablenames_cursor
RETURN
SET ANSI_NULLS ON
Summary Data Dictionary Creator (DDC) is a simple application which helps you document SQL Server databases.
Can someone tell me if both the sysobject/syscolumns and the extended property data is stored within the corresponding dbase? Or is it stored in Master or msdb? I'm trying to determine if my DR stategy needs to change if I begin to use this in a prod environment.
I can recommend SqlSpec as a very comprehensive data dictionary generator. It's available at http://www.elsasoft.org
how can i create data dictionary of required/selected tables from data base in sql server
how can create Data dictionary in sql server 2005
i have prblem in above script it gives error in
insert DataD select
and
what is the syntex of this in sql server 2005
plz give me answer very urgent
Hi I am not able to run this code from .sql file using MS SQL 2005. I got an error
Msg 468, Level 16, State 9, Line 20
Cannot resolve the collation conflict between "Latin1_General_CI_AI" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
Msg 468, Level 16, State 9, Line 33
Please help to resove the problem
Sorry guys, but I haven't had any issues with running this in Sql Server 2005.
Ok, finally ran into the COLLATION issue. In the joins for pulling descriptions, change them to read:
on o.name COLLATE Latin1_General_CI_AS = e.objname
on c.name COLLATE Latin1_General_CI_AS = e.objname
Generate Sql Server data dictionary table
If you're getting error
then change the joins to
o.name COLLATE Latin1_General_CI_AS = e.objname
forums.microsoft.com/.../ShowPost.aspx
Pingback from Quick Data Dictionary « Jeff Maass’s Development Toolkit
COLLATE Latin1_General_CI_AS - Works Wonders! Thanks for the great solution.