|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Friday, May 28, 2010 9:56 AM
Points: 77,
Visits: 248
|
|
I want to create a text file summary of the schematics for a database. Essentially, I want to have what is output for sp_help objectname, but for every object in the database. I can generate the script for the entire database, and that might work, but I don't really want a SQL script, just a summary of the schema (table/object names, field and column names, and datatypes and lengths. Keys and indexes would be nice, too).
A diagram isn't really what I'm after, either, as I think that would be unwieldy, plus I don't really want to have to drag and arrange every single table image in the diagram to get it to look right. I'm thinking a text file would be best.
I thought maybe I could create a cursor and loop through the objects or something, but don't really know what/how the output of running sp_help objectname would work - can I output to text somehow?
Maybe there's another tool or script that would do what I want? Thanks for any info or help!
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Saturday, May 04, 2013 11:13 AM
Points: 9,855,
Visits: 9,374
|
|
This should do it:
Declare @sql Nvarchar(MAX) Set @sql = N''
Select @sql = @sql + N' EXEC sp_help ''['+TABLE_SCHEMA+N'].['+TABLE_NAME+N']'';' From INFORMATION_SCHEMA.TABLES Print N'Executing: '+@sql+' ' EXEC(@sql)
-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung Proactive Performance Solutions, Inc. "Performance is our middle name."
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, August 31, 2012 6:08 AM
Points: 322,
Visits: 459
|
|
Pete T (1/5/2009) I want to create a text file summary of the schematics for a database. Essentially, I want to have what is output for sp_help objectname, but for every object in the database. I can generate the script for the entire database, and that might work, but I don't really want a SQL script, just a summary of the schema (table/object names, field and column names, and datatypes and lengths. Keys and indexes would be nice, too).
A diagram isn't really what I'm after, either, as I think that would be unwieldy, plus I don't really want to have to drag and arrange every single table image in the diagram to get it to look right. I'm thinking a text file would be best.
I thought maybe I could create a cursor and loop through the objects or something, but don't really know what/how the output of running sp_help objectname would work - can I output to text somehow?
Maybe there's another tool or script that would do what I want? Thanks for any info or help!
use master go select * into table_help from information_schema.columns GO
DECLARE @sql varchar(8000) DECLARE @BAK_PATH VARCHAR(4000) declare c_bak cursor FAST_FORWARD FOR select name from sys.databases where name <> 'master' OPEN c_bak FETCH NEXT FROM c_bak INTO @BAK_PATH WHILE @@FETCH_STATUS = 0 BEGIN SET @SQL = 'use '+@BAK_PATH+'; insert into table_help select * from information_schema.tables;' PRINT (@SQL) EXEC(@SQL) FETCH NEXT FROM c_bak INTO @BAK_PATH END CLOSE C_BAK DEALLOCATE C_BAK
select * from table_help GO
_____________________________________________________________________________________________________________ Paresh Prajapati
+919924626601 http://paresh-sqldba.blogspot.com/ LinkedIn | Tweet Me | FaceBook | Brijj
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Saturday, May 04, 2013 11:13 AM
Points: 9,855,
Visits: 9,374
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 5:02 AM
Points: 2,365,
Visits: 1,825
|
|
RBarryYoung (1/5/2009)
This should do it: Declare @sql Nvarchar(MAX) Set @sql = N''
Select @sql = @sql + N' EXEC sp_help ''['+TABLE_SCHEMA+N'].['+TABLE_NAME+N']'';' From INFORMATION_SCHEMA.TABLES Print N'Executing: '+@sql+' ' EXEC(@sql)
:)
"Keep Trying"
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, February 15, 2013 4:42 AM
Points: 1,798,
Visits: 177
|
|
Make use of Un Documented sp_MSForEachDB and sp_MSForEachTable
EXEC sp_MSForeachdb 'SELECT * FROM ?.INFORMATION_SCHEMA.TABLES' The ? is a way to represent the name of the database. This returns multiple result sets, but is the best you are going to get out of the box. Mainly, there is no consolidated metadata for the server. Each database hosts its own metadata.
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Saturday, May 04, 2013 11:13 AM
Points: 9,855,
Visits: 9,374
|
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Friday, May 28, 2010 9:56 AM
Points: 77,
Visits: 248
|
|
| Interesting - thanks for all the replies! I'll play with it some more today and see what happens!
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 12:41 PM
Points: 174,
Visits: 247
|
|
Is there anyway that you could capture the output of sp_help <table_name> to some table. You know what I mean ?
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Saturday, May 04, 2013 11:13 AM
Points: 9,855,
Visits: 9,374
|
|
|
|
|