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.
Here what you have to do:
- right click the database (not the table) and select tasks --> generate scripts
- Next --> select the requested table/tables (from select specific database objects)
- next --> click advanced --> types of data to script = schema and data
- next and finish
Here You can see step by step process of Generate script in SQL Server Management Studio :
Step 1: Right Click on Your Database --> Select Task-->Generate Script..
Step 2: Select Next in Script Wizard
Step 3: Select Script Entire Database
Step 4:Choose Your File Name
and Finish
Now you can use your script file.
来源:https://stackoverflow.com/questions/9429902/generate-script-in-sql-server-management-studio