Tuesday 22 March 2011

How to Generate the Scripts for Table with data in sql server 2005

This is the problem I faced when I want to change the schema and adding a new column to table which has lot of records. while adding a column it is showing timeout. I deleted the data from the table and added the column. But i want to insert the same data which has before delete.  Then I get a question that How i can generate scripts along with data in Sql Server 2005?. The sql server 2005 doesnot have generate script along with data facility.

Solution for SQL SERVER – 2005 – Create Script to Copy Database Schema and All The Objects – Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects:

  1. First of all install Database Publishing Wizard from here : Download Database Publishing Wizard. It will be installed at following location : C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\

  2. Now  goto Command prompt and run following command on any desire database, it will create the script at your specified location. Script will have schema as well as data which can be used to create the same information on new server.


Examples:

Command to run which will create schema and database:
C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz script -d AdventureWorks “C:\AdventureWorks.sql”

Command to run which will create schema:
C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz script -d AdventureWorks “C:\AdventureWorks.sql” -schemaonly

Command to run which will create data:
C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz script -d AdventureWorks “C:\AdventureWorks.sql” -dataonly

Note: I suggest that you try this on smaller database of size around 100MB.

Reference : Database Publishing Wizard

No comments:

Post a Comment