x
login about faq Site discussion (meta-askssc)

Automatic generate table script.

Hi, Is there any way to generate the create table script in sql automatically?

Example: Say i have 50 tables i dont want to go and find the table script for each table. instead is there a way to generate the create table script automatically. Thanks Satish

more ▼

asked Jul 31 '12 at 07:15 PM in Default

Satish17 gravatar image

Satish17
0 2 2

(comments are locked)
10|1200 characters needed characters left

4 answers: sort voted first

You can use SMO with powershell to script all the tables.

Here is an article that shows how to script all the views (just replace that with tables): http://philergia.wordpress.com/2011/02/28/using-powershell-and-smo-to-script-sql-server-database-objects-3/

more ▼

answered Jul 31 '12 at 07:32 PM

KenJ gravatar image

KenJ
12.4k 2 10

(comments are locked)
10|1200 characters needed characters left

my quick and dirty solution: right click on the database -> Tasks -> Generate Scripts and then go through the wizard

It's really the lazy solution

regards Dirk

more ▼

answered Jul 31 '12 at 07:32 PM

DirkHondong gravatar image

DirkHondong
1.3k 7 14 17

(comments are locked)
10|1200 characters needed characters left

Dirk, Thanks for the reply., actually i just given an example of 50 tables but indeed i have lot of tables to do in that case this solution right click on the database -> Tasks -> Generate Scripts will not work as it takes much more time :)

Thanks Satish

more ▼

answered Jul 31 '12 at 07:39 PM

Satish17 gravatar image

Satish17
0 2 2

Ha! I know what you mean. In that case Ken has the better answer. That should fit very well

Jul 31 '12 at 07:42 PM DirkHondong
(comments are locked)
10|1200 characters needed characters left

Ken, the query is seems to be complex and confusing is there anything easy?

more ▼

answered Jul 31 '12 at 09:15 PM

Satish17 gravatar image

Satish17
0 2 2

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x600

asked: Jul 31 '12 at 07:15 PM

Seen: 343 times

Last Updated: Jul 31 '12 at 09:15 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.