 |
|
 |
Works perfectly with SQL Server 2008 R2!
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Very nice script to document a database very fast.
Thank you.
Micke
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Thanks, really neat and useful.
|
|
|
|
 |
|
|
 |
|
 |
This is very helpful and excellent script. Thanks man!!!
|
|
|
|
 |
|
 |
Excellent script.
Thanks!
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Thank you very much. You saved my day today. This is exactly what I am looking for.
|
|
|
|
 |
|
 |
Hello,
I am web developer.
And It help me a lot to understand our old database.
Thank you so much.
|
|
|
|
 |
|
 |
Clean, simple to use... unbelieable !!!
|
|
|
|
 |
|
 |
Hello
Thank you very much for your work.
it is perfect!!!!!
|
|
|
|
 |
|
|
 |
|
 |
Thanks a lot for your effort, this an excelent time saver.
|
|
|
|
 |
|
 |
This is a good efforts!!!
|
|
|
|
 |
|
|
 |
|
 |
This is very good. Very useful.
How about stored procedures ?
Can we get out from this . It would me even better.
Thanks Heapsmodified on Saturday, February 27, 2010 4:34 PM
|
|
|
|
 |
|
 |
| It worked perfectly! Nice job! Miguel Guzmán-Centeno
Software Developer
|
|
|
|
 |
|
 |
Muchas gracias por el código q publicaste...
En esta nueva versión cambié palabras en inglés a español y con la ayuda del agregado de Store Procedures propuesto por el otro compañero, le agregué store procedures para SQL Srv 2005, además muestra el código de los store procedures
http://rapidshare.com/files/322251328/DB_Document_Version_1.2.sql[^]
Truncate Table #StoredProcedures
IF @SqlVersion = '2000'
BEGIN
INSERT INTO #StoredProcedures(object_id, name, type, [description], Code)
SELECT so.id, '[dbo].[' + CAST(so.name AS varchar(155)) + ']', 'Procedimiento Almacenado', (SELECT CAST(sp.value AS varchar(4000)) FROM sysproperties sp WHERE sp.id = so.id) AS Comment, ''
FROM sysobjects so WHERE so.type ='P' AND so.Category <> 2
END
else if @SqlVersion = '2005'
begin
insert into #StoredProcedures (Object_id, Name, Type, [description], Code)
--FOR 2005
Select o.object_id, '[' + s.name + '].[' + o.name + ']',
'Procedimiento Almacenado',
cast(p.value as varchar(4000)),
ISNULL(smsp.definition, ssmsp.definition)
from sys.objects o
left outer join sys.schemas s on s.schema_id = o.schema_id
left outer join sys.extended_properties p on p.major_id = o.object_id and minor_id = 0 and p.name = 'MS_Description'
LEFT OUTER JOIN sys.sql_modules AS smsp ON smsp.object_id = o.object_id
LEFT OUTER JOIN sys.system_sql_modules AS ssmsp ON ssmsp.object_id = o.object_id
where type = 'P'
order by type, s.name, o.name
end
SET @MaxK = (SELECT COUNT(id) FROM #StoredProcedures)
SET @k = 1
set @sr = 1
print '<table border="0" cellspacing="0" cellpadding="0" width="100%" id = "index2"><tr><td><b>Procedimientos Almacenados</b></td></tr></table>'
print '<table border="0" cellspacing="1" cellpadding="0" width="100%"><tr><th>Num</th><th>Nombre</th><th>Tipo</th></tr>'
set @Output = ''
set @last = ''
set @current = ''
WHILE(@k <= @MaxK)
BEGIN
SELECT @Output = '<tr><td align="center">' + Cast((@k) as varchar) + '</td><td><a href="#' + Type + ':' + name + '">' + name + '</a></td><td>' + Type + '</td></tr>'
from #StoredProcedures where id = @k
PRINT @Output
SET @k = @k + 1
END
print '</table><br />'
Truncate Table #SpColumns
SET @k = 1
WHILE(@k <= @maxk)
BEGIN
--table header
SELECT @Output = '<tr><th align="left"><a name="' + Type + ':' + name + '"></a><b>' + Type + ':' + name + '</b></th></tr>', @description = [description]
FROM #StoredProcedures WHERE id = @k
PRINT '<br /><br /><br /><table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td align="right"><a href="#index2">Indice</a></td></tr>'
PRINT @Output
PRINT '</table><br />'
PRINT '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td><b>Descripcion</b></td></tr><tr><td>' + isnull(@description, '') + '</td></tr></table><br />'
--table SpColumns
-- look in the syscoloumns table to get the coloumn (input, output parameters) names
INSERT INTO #SpColumns (Name, Type, Output)
--FOR 2000
SELECT sc.name, st.name + (
CASE WHEN (st.name = 'varchar' or st.name = 'nvarchar' or st.name ='char' or st.name ='nchar')
THEN '(' + cast(sc.length as varchar) + ')'
WHEN st.name = 'decimal'
THEN '(' + cast(sc.prec as varchar) + ',' + cast(sc.scale as varchar) + ')'
ELSE ''
END )
, isOutparam
FROM syscolumns sc, master..systypes st, sysobjects so
WHERE so.id = (SELECT SP.object_id FROM #StoredProcedures SP
WHERE SP.ID = @k)
AND sc.id = so.id
AND sc.xtype = st.xtype
SET @maxj = @@rowcount
SET @j = 1
PRINT '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td><b>Columnas</b></td></tr></table>'
PRINT '<table border="0" cellspacing="1" cellpadding="0" width="100%"><tr><th>Num</th><th>Nombre</th><th>Tipo</th><th>Col. Salida</th></tr>'
WHILE(@j <= @maxj)
BEGIN
SELECT @Output = '<tr><td width="20px" align="center">' + Cast((@j) as varchar) + '</td><td width="150px">' + isnull(name,'') + '</td><td width="150px">' + upper(isnull(Type,'')) + '</td><td width="50px" align="center">' + isnull(Output,'0') + '</td></tr>'
FROM #SpColumns WHERE id = @j
PRINT @Output
SET @j = @j + 1;
END
-- Obtain sp code
declare @LargoCodigoSP as int
set @LargoCodigoSP = (select LEN(Code) FROM #StoredProcedures WHERE id = @k)
declare @InicioBloqueSp as int, @LargoBloqueSP as int
declare @Out1 as varchar(max)
set @InicioBloqueSP = 1
if (@LargoCodigoSp > 7900)
Begin
set @LargoBloqueSP = 7900
End
Else
Begin
set @LargoBloqueSP = @LargoCodigoSP
End
PRINT '<tr><td align="left" colspan="4"><div class="code-comment">'
while (@InicioBloqueSP < @LargoCodigoSP)
Begin
set @Out1 = (select substring(Code,@InicioBloqueSP,@LargoBloqueSP) FROM #StoredProcedures WHERE id = @k)
--reemplazar los cambios de linea
set @Out1 = (Select REPLACE(@Out1,'
', '<br />'))
print @Out1
set @InicioBloqueSP = @InicioBloqueSP + @LargoBloqueSP
set @LargoBloqueSP = 7900
if (@LargoBloqueSP > (@LargoCodigoSP - @InicioBloqueSP))
Begin
set @LargoBloqueSP = @LargoCodigoSP - @InicioBloqueSP + 1
End
End
PRINT '</div></td></tr>'
PRINT '</table><br />'
SET @k = @k + 1;
END
Ronald Fallas
|
|
|
|
 |
|
 |
Hay una pulguita con el truncate de #SpColumns, hay q ponerlo dentro del While
Truncate Table #SpColumns
INSERT INTO #SpColumns (Name, Type, Output)
Ronald Fallas
|
|
|
|
 |
|
 |
Very useful, it would be perfect if could add sql 2005/2008 code for table-valued & scalar functions, and stored procedures. (Also could be turned into a stored procedure with parameter of output html file, and load or print option.)
|
|
|
|
 |