Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate script in SQL Server Management Studio

If I have a table with data in a database in SQL Server, how can I generate a script that will create the table and add the data too?

If I right click on the table then select Script Table As > Create to > File, that generates a script to just create the table without the data. What I need is a script that creates the table and adds the data that is already existing in the table or 2 separate scripts, one that creates the table and one that adds the data.

like image 881
General_9 Avatar asked Feb 24 '12 11:02

General_9


People also ask

How do you generate create table script for all tables in SQL Server database?

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.


2 Answers

Here what you have to do:

  1. right click the database (not the table) and select tasks --> generate scripts
  2. Next --> select the requested table/tables (from select specific database objects)
  3. next --> click advanced --> types of data to script = schema and data
  4. next and finish
like image 146
Alex Avatar answered Sep 24 '22 00:09

Alex


Use SSMS scripting feature (Rightclick on database->Tasks->Generate Scripts)

or

use SSMS Tools Pack

like image 42
Oleg Dok Avatar answered Sep 23 '22 00:09

Oleg Dok