Ayuda urgente!!!

10/07/2003 - 21:36 por John Alexander Gomez | Informe spam
Buenas Tardes!!
Quiero hacer una documentación de mi B.D., es decir,
imprimir nombres de tablas, campos, propiedades de los
campos, etc, (como se hace en el access con el
documentador).

Alguien me puede decir si es posible y como?

Muchas gracias!!!
 

Leer las respuestas

#1 Pedro Arciniegas
10/07/2003 - 22:07 | Informe spam
Hola,

No puedes hacerlo de forma directa, tienes que escribir
algo de código.
Puedes extraer toda la información que necesitas de las
tablas y vistas del sistema.

Podrías usar un script como este.

/*** Inicio ****/

create table #tables
(id int primary key,
tableName sysname,
description varchar(7500),
type varchar(2))
go

create table #columns
(parentId int,
columnName sysname,
description varchar(6500),
type sysname,
[precision] int,
scale int null,
isOutParam bit,
isNullable bit,
isIdentity bit,
defaultValue varchar(1000))
go

create table #indices
(parentId int,
indexName sysname,
[fillFactor] int,
[clustered] bit,
primaryKey bit,
[unique] bit)
go

create table #indexColumns
(parentId int,
indexName sysname,
columnName sysname,
[order] smallint)
go

create table #fKeys
(parentId int,
fkName sysname,
rkName sysname)
go

create table #triggers
(parentId int,
tiggerName sysname,
[description] varchar(6500),
[update] bit,
[insert] bit,
[delete] bit,
insteadOf bit,
author varchar(1000),
[date] varchar(50))
go

create table #procedures
(procedureName sysname,
[description] varchar(6500),
author varchar(1000),
[date] varchar(50))
go

create table #functions
(functionName sysname,
[description] varchar(6500),
functionType varchar(2),
author varchar(1000),
[date] varchar(50))
go

insert into #tables
select o.id tableId, o.name tableName,
cast(p.value as varchar(8000)) description,
o.xtype
from sysobjects o
left join sysproperties p on o.id = p.id
where o.xtype in ('u', 'v')
and objectproperty(o.id, 'IsMsShipped') = 0
and p.smallid = 0
and p.name = 'MS_Description'
order by o.name
go

insert into #columns
select c.id parentId, c.name columnName,
cast(p.value as varchar(8000)) description,
t.name type, c.prec [precision], c.scale scale,
c.isoutparam isOutParam,
c.isnullable isNullable, (colstat & 1) isIdentity,
m.text defaultValue
from syscolumns c
inner join sysobjects o on c.id = o.id
inner join systypes t on c.xtype = t.xtype
left join sysproperties p on c.id = p.id and c.colid =
p.smallid and p.name = 'MS_Description'
left join syscomments m on c.cdefault = m.id
where o.xtype in ('u', 'p', 'v')
and t.xtype = t.xusertype
order by c.name
go

insert into #indices
select i.id parentId, i.name, i.origfillfactor
[fillFactor],
case i.indid when 1 then '1' else 0 end
[clustered],
case (i.status & 2048) when 2048 then 1 else 0
end primaryKey,
case (i.status & 0x1000) when 0x1000 then 1 else
0 end [unique]
from sysindexes i
inner join sysobjects o on i.id = o.id
where not i.indid in (0, 255)
and (i.status & 32) = 0 -- no incluir los indices del
sistema
and o.xtype in ('u', 'v')
go

insert into #indexColumns
select o.id parentId, i.name indexName, c.name
columnName, k.keyno [order]
from sysobjects o
inner join sysindexes i on o.id = i.id
inner join sysindexkeys k on i.id = k.id
inner join syscolumns c on k.id = c.id and k.colid =
c.colid
where o.xtype in ('u', 'v')
and (i.status & 32) = 0 -- no incluir los indices del
sistema
go

insert into #fKeys
select r.fkeyid parentId, o.name fkName, i.name rkName
from sysreferences r
inner join sysobjects o on r.constid = o.id
inner join sysindexes i on r.rkeyid = i.id and
r.rkeyindid = i.indid
go

insert into #triggers
select o.parent_obj parentId, o.name triggerName,
cast(pd.value as varchar(7500)) description,
objectproperty(o.id, 'ExecIsUpdateTrigger')
[update],
objectproperty(o.id, 'ExecIsInsertTrigger')
[insert],
objectproperty(o.id, 'ExecIsDeleteTrigger')
[delete],
objectproperty(o.id, 'ExecIsInsteadOfTrigger')
[inSteadOf],
cast(pa.value as varchar(7500)) author,
cast(pc.value as varchar(7500)) [date]
from sysobjects o
left join sysproperties pd on o.id = pd.id and pd.name
= 'MS_Description'
left join sysproperties pa on o.id = pa.id and pa.name
= 'Author'
left join sysproperties pc on o.id = pc.id and pc.name
= 'date'
where o.xtype = 'tr'
go

insert into #procedures
select o.name procedureName,
cast(pd.value as varchar(7500)) description,
cast(pa.value as varchar(7500)) author,
cast(pc.value as varchar(7500)) [date]
from sysobjects o
left join sysproperties pd on o.id = pd.id and pd.name
= 'MS_Description'
left join sysproperties pa on o.id = pa.id and pa.name
= 'Author'
left join sysproperties pc on o.id = pc.id and pc.name
= 'date'
where o.xtype = 'p'
go

insert into #functions
select o.name functionName,
cast(pd.value as varchar(7500)) description,
o.xtype functionType,
cast(pa.value as varchar(7500)) author,
cast(pc.value as varchar(7500)) [date]
from sysobjects o
left join sysproperties pd on o.id = pd.id and pd.name
= 'MS_Description'
left join sysproperties pa on o.id = pa.id and pa.name
= 'Author'
left join sysproperties pc on o.id = pc.id and pc.name
= 'date'
where o.xtype in ('fn', 'if', 'tf')
go

select * from #tables
select * from #columns
select * from #indices
select * from #indexColumns
select * from #fKeys
select * from #triggers
select * from #procedures
select * from #functions

drop table #tables
drop table #columns
drop table #indices
drop table #indexColumns
drop table #fKeys
drop table #triggers
drop table #procedures
drop table #functions

/**** Fin ****/


Buenas Tardes!!
Quiero hacer una documentación de mi B.D., es decir,
imprimir nombres de tablas, campos, propiedades de los
campos, etc, (como se hace en el access con el
documentador).

Alguien me puede decir si es posible y como?

Muchas gracias!!!

.

Preguntas similares