How To Generate Scripts of all tables with data in sql server 2008


MS SQL Server 2008 has new Generate Scripts option which enables sql programmers to script data in SQL Server database tables. SQL developers can script data from sql tables into a script file, to the clipboard or script data on a new sql query window. Script data can be used to export and/or import table data from one database to another database.

The Script Data option creates INSERT statements foreach row in the table using the column data that the related table record has.

Requirement:
I have a database name as “sanjeet”. In that database some tables are there. My requirement is to generate scripts of all tables,tables data and all stored procedure present in that database.

Solution:
1. Open sql server. Right click on the database name and open the context menu, choose Tasks menu and open submenu. Select Generate Script submenu item from the displayed list.

2.      Click on Next.

3.     If you want to select particular table and stored procedure script then select "Select Specific Database Object" option.Then select your required table and procedure from below. Click on next.

4.     If you want to generate table structure script with data then click on advance option.
      
 5.    Choose "Schema and Object" option.


6.    Output Option screen in the Generate Script Wizard is the screen where a sql administrator or a programmer can make a selection among the existing output options. The script generator can create the desired scripts in the forms of a file, also can split the automatic generated script per object basis, or define the file as a unicode file or in ANSI text. A database developer can also select the file name and the output file folder for the script engine to create and place the script file. Click on Next.

7.     Click on Next.
  
8.      Generate Script Progress screen displays the status of the scripting operation. If an error occurs sql developers and administrators can find the error details on this screen. If everything runs without any error and does not fail, you will see Success status for each scripting action on the progress screen.


9.      Since as the output option for the scripting, the New Query Window is selected, the final script is displayed on the SQL Server Management Studio Query Editor window as shown below.

      
       

Comments