SQL Server: Export Specific Table to SQL Query CREATE and INSERT

For the sample, I have a database named SRA and I want to export a table named category into SQL format with CREATE TABLE and INSERT data query. 

First, open the Microsoft SQL Server Management Studio then Connect to the database. The category table is as you can see in the image below.


Right-click on the SRA database node in Object Explorer then choose Tasks - > Generate Scripts...


However, this database has only 1 table but to pick a specific table to export choose "Select specific database object", check on the object/table that you want to be exported. Then click Next.


Because we want to export with "create" and insert "query", we need to click the Advanced button. 


Find the "Types of data to script" option and choose "Schema and Data", then click OK.


The next step is up to you. If you want it to be saved into a file then choose the "Save to File" option, or you want to keep it in a clipboard for copy-paste then choose "Save to Clipboard". I usually choose "Save to new query window", so it will appear on a new query window. Then click Next.


It will display the summary of the chosen option then click Next again.


Wait until the process is finished then click Finish.


Here is the result:


Post a Comment

0 Comments