Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate create script of table using SQL query in SQL Server

I want to generate create table script of already created table in my live database.

I know we can generate scripts using right click on table and click on 'script table as' menu and script will be generated. Because my live db UI is running very slow.

I want to do same process using SQL query. is there any way??

like image 771
Pankaj Agarwal Avatar asked Nov 18 '10 10:11

Pankaj Agarwal


People also ask

How do I create a script in SQL Server?

Open the SQL Server Management Studio. In the Object Explorer, expand Databases, and then locate the database that you want to script. Right-click the database, point to Tasks, and then select Generate Scripts.


1 Answers

If you are looking for a TSQL solution, it is quite verbose, as this example shows.

A shorter alternative would be using the SMO library (example)

(I originally answered this here, but SQL Server-only devs probably do not relate the question title to this problem)

like image 174
devio Avatar answered Sep 29 '22 08:09

devio