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 '12 at 07:15 PM in Default

Satish17 gravatar image

Satish17
0 2 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
19.1k 1 3 11

(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 14 17 19

(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 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 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.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

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:

x672

asked: Jul 31 '12 at 07:15 PM

Seen: 765 times

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