Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

how to script out create table script of all tables in a database Expand / Collapse
Author
Message
Posted Tuesday, August 6, 2013 7:52 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 7:33 AM
Points: 414, Visits: 2,087
I would like to script out all create table script in a database and save it in a table. How to perform this operation?
Post #1481334
Posted Tuesday, August 6, 2013 8:05 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: 2 days ago @ 4:01 PM
Points: 1,471, Visits: 8,358

Why do you want to do this? All the information in the script is already available in system tables and views.




Alvin Ramard
Memphis PASS Chapter

All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.
Post #1481343
Posted Tuesday, August 6, 2013 8:14 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 7:33 AM
Points: 414, Visits: 2,087
I am working on a project to help developers to know the relationship between the tables. Let us assume pk in table A is foreign key constrain in table B,C and D. So I want to display all the table info in a window. Kind of ERD but as we have too many tables in our prod environment its' not possible to display all the table info in a single window.
Post #1481351
Posted Tuesday, August 6, 2013 8:20 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:10 AM
Points: 13,230, Visits: 12,709
muthyala_51 (8/6/2013)
I am working on a project to help developers to know the relationship between the tables. Let us assume pk in table A is foreign key constrain in table B,C and D. So I want to display all the table info in a window. Kind of ERD but as we have too many tables in our prod environment its' not possible to display all the table info in a single window.


Why not use a database diagram? That is pretty much what they are intended to be used for.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1481358
Posted Tuesday, August 6, 2013 8:31 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: 2 days ago @ 4:01 PM
Points: 1,471, Visits: 8,358

You should be able to get all you need from these views:

INFORMATION_SCHEMA.TABLES
INFORMATION_SCHEMA.COLUMNS

sys.schemas
sys.tables
sys.columns

There may be other system tables or views that could be helpful. You just need to take the time to learn what's available in system views.




Alvin Ramard
Memphis PASS Chapter

All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.
Post #1481365
Posted Tuesday, August 6, 2013 8:34 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 7:33 AM
Points: 414, Visits: 2,087

Why not use a database diagram? That is pretty much what they are intended to be used for.


The problem is we have too many tables which are inter related. If we go with database diagram it will be a huge figure with too much information. I am just trying to stream line the process which will be easy for new developers to understand the database structure.
Post #1481370
Posted Tuesday, August 6, 2013 8:36 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:10 AM
Points: 13,230, Visits: 12,709
muthyala_51 (8/6/2013)

Why not use a database diagram? That is pretty much what they are intended to be used for.


The problem is we have too many tables which are inter related. If we go with database diagram it will be a huge figure with too much information. I am just trying to stream line the process which will be easy for new developers to understand the database structure.


Understood. The main advantage of the diagram is that you don't have to include every single table. I have often used diagrams as a learning tool for new employees. Just cut down the number of tables and explain that there are some additional tables but the diagram is only showing the major ones.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1481373
Posted Tuesday, August 6, 2013 8:41 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 1:05 PM
Points: 2,834, Visits: 8,544
In answer to your original question: Display the tables in the "Object Explorer" window. Then select the tables you want (all or some), right click, "Script Table as Create", then choose the option you want.

Go to "Tools -> Options -> Scripting" to modify scripting rules.



Post #1481377
Posted Tuesday, August 6, 2013 8:45 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 7:33 AM
Points: 414, Visits: 2,087
I am planning to work on a dashboard kind of tool , such like when we click on a table it should display all the tables dependent on it and if we like to see the structure, it should be able to display the structure of all the tables.
Post #1481378
Posted Wednesday, August 7, 2013 8:06 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 7:33 AM
Points: 414, Visits: 2,087
do we have any already built in tools which will help me to achieve this? I tried to use Dezign which works better to some extent. Any suggestions?
Post #1481883
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse