Search code examples
sql-serversql-server-2008ssms

SQL server convert entire table to a script?


I want to create my ENTIRE table as a script - columns, constraints, rows etc. as a script in SQL server management studio. How do I do this ?


Solution

  • Right click on the database in your Object Explorer. Go to Tasks > Generate Scripts.

    enter image description here

    Choose "Select specified objects" and expand tables and select the table you want. On the "Set Script Options" page, click advanced and make sure you have all your table related stuff set to true. There is also a field in Advanced called "Types of data to script" - set that to "Schema and Data" to include INSERT statements.

    Note: I'm referencing Management Studio 2012 for SQL Standard. I assume it's the same for 2008, but I could be wrong...

    enter image description here