SQL SERVER – 2008 – Copy Database With Data – Generate T-SQL For Inserting Data From One Table to Another Table

Just about a year ago, I had written on the subject of how to insert data from one table to another table without generating any script or using wizard in my article SQL SERVER – Insert Data From One Table to Another Table – INSERT INTO SELECT – SELECT INTO TABLE. Today, we will go over a similar question regarding how to generate script for data from database as well as table. SQL Server 2008 has simplified everything.

Let us take a look at an example where we will generate script database. In our example, we will just take one table for convenience.

Right Click on Database >> Tasks >> Generate Scripts >>

SQL SERVER - 2008 - Copy Database With Data - Generate T-SQL For Inserting Data From One Table to Another Table data1

SQL SERVER - 2008 - Copy Database With Data - Generate T-SQL For Inserting Data From One Table to Another Table data2

This will pop up Generate SQL Server Scripts Wizards >> Click on Next >> Select Database >> This will bring up a screen that will suggest to Choose Script Option.

SQL SERVER - 2008 - Copy Database With Data - Generate T-SQL For Inserting Data From One Table to Another Table data3

On Choose Script Option Screen of Script Wizard under section Table/View Options Look at Script Data row and Turn the Option to True.

SQL SERVER - 2008 - Copy Database With Data - Generate T-SQL For Inserting Data From One Table to Another Table data4

The Next Screen will ask about object types. Select all the objects that are required in the generated script. Depending on the previous screen it will show few more screen requesting details about the objects required in script generation.

SQL SERVER - 2008 - Copy Database With Data - Generate T-SQL For Inserting Data From One Table to Another Table data5

SQL SERVER - 2008 - Copy Database With Data - Generate T-SQL For Inserting Data From One Table to Another Table data6

On the very last screen it will request output options. Select the desired output options of Script to file, Script to Clipboard or Script New Query Window.3

SQL SERVER - 2008 - Copy Database With Data - Generate T-SQL For Inserting Data From One Table to Another Table data7

Clicking on Finish button will generate a review screen containing the required objects along with script generating data.

SQL SERVER - 2008 - Copy Database With Data - Generate T-SQL For Inserting Data From One Table to Another Table data8

SQL SERVER - 2008 - Copy Database With Data - Generate T-SQL For Inserting Data From One Table to Another Table data9

Clicking on Finish button one more time will generate the requested output.

SQL SERVER - 2008 - Copy Database With Data - Generate T-SQL For Inserting Data From One Table to Another Table data10

Similarly, if you want to generate data for only one table, you can right click on the table and follow almost a similar wizard. I am sure this neat feature will help everybody who has been requesting for it for a long time.

Watch SQL in Sixty Seconds Episode on same subject.

[youtube=http://www.youtube.com/watch?v=lSh3fq-MikE]

Reference : Pinal Dave (https://darkslategrey-bat-805937.hostingersite.com)

Best Practices, Database, DBA, SQL Scripts, SQL Utility
Previous Post
SQL SERVER – 2008 – Design Process Decision Flow
Next Post
SQLAuthority News – Author’s Birthday – Top 7 Commenters – Volunteers

Related Posts

Leave a Reply