12

I need to create the SQL code that in its output will return the CREATE TABLE SQL for all tables in current database.

Any suggestions?

3
  • Is there an analog of MySQL's "SHOW CREATE TABLE" that you can use? Commented Sep 16, 2015 at 11:52
  • possible duplicate of Create SQL script that create database and tables Commented Sep 16, 2015 at 11:55
  • Hmmm - seems not -- see here Commented Sep 16, 2015 at 11:55

2 Answers 2

36

In SQL Server Management Studio(SSMS)

Right click on the DB_NAME -> Select Task -> Select Generate Script.

Follow along the presented wizard and select all tables in that database to generate the scripts.

Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't answer the OP question. They were looking for a SQL script to perform this action.
@DaleK See my comment on your answer. Any others that come looking, the answer is at stackoverflow.com/questions/706664/…
0

Use a Visual Studio SQL Server Database Project as follows:

  1. Create a Visual Studio SQL Server Database Project.

enter image description here

  1. From the Project Menu, select Import > Database ...

  2. Right click on the project and click publish.

3 Comments

Thank you for this answer. I really love the ability to create database projects from existing databases. You can even track changes between your prod/dev DBs. Totally underrated answer!
This doesn't answer the OP question. They were looking for a SQL script to perform this action.
@DaleK I think you misunderstood the question. The OP wanted a SQL script that would generate the create scripts. Anyone could use SSMS or Visual Studio, but that doesn't satisfy unattended scripting needs. The correct answer can be found at stackoverflow.com/questions/706664/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.