x

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, 2012 at 07:15 PM in Default

avatar image

Satish17
0 2 2 3

(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, 2012 at 07:32 PM

avatar image

KenJ
24.5k 3 10 19

(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, 2012 at 07:32 PM

avatar image

DirkHondong
1.3k 15 19 24

(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, 2012 at 07:39 PM

avatar image

Satish17
0 2 2 3

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

Jul 31, 2012 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, 2012 at 09:15 PM

avatar image

Satish17
0 2 2 3

(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

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x993

asked: Jul 31, 2012 at 07:15 PM

Seen: 1316 times

Last Updated: Jul 31, 2012 at 09:15 PM

Copyright 2016 Redgate Software. Privacy Policy