In this example, have created Persons Table with the data. Will see how to export the table schema and data with insert statements.
Follow the below steps.
Step 1: Open SQL Server Management Studio. Connect to the required Database.
Step 2: Right click on the required Database (where the actual table is available) from the Object Explorer, select Tasks and click on Generate Scripts…
Step 3: Generate and Publish Scripts windows is displayed as shown below. Click on Next.
Step 4: Select the “Select specific database objects” and select dbo.Persons table. Click on Next.
Step 5: Choose the File name and Path. Click on Advanced.
Step 6: Under Options, Select Types of data to script as Schema and data. Click on OK.
Note:
- Data only, data alone exported.
- Schema and data, Table schema and data also exported.
- Schema only, Table schema alone exported.
Step 7: At this step, can see the summary of our selection. Click on Next.
Step 8: Status of our Data and Schema export can be seen at this step. Click on Finish.
Step 9: Open the file as provided the path in the Step 5 to see the file created by SQL Server.
Below is the output. We can see the Table Schema and Insert Statements.
Using this scripts, we can easily execute the commands to create the table and insert the data in any SQL environments.
Hope you liked the post.