Click here to Skip to main content
6,594,088 members and growing! (13,867 online)
Email Password   helpLost your password?
Database » Database » General     Intermediate

SQL SERVER - 2005 - Generate Script with Data from Database - Database Publishing Wizard

By pinaldave

SQL SERVER - 2005 - Generate Script with Data from Database - Database Publishing Wizard
C++, SQL, Windows, Visual Studio, SQL 2005, DBA, Dev
Posted:17 Nov 2007
Views:21,511
Bookmarked:23 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
10 votes for this article.
Popularity: 4.42 Rating: 4.42 out of 5
1 vote, 10.0%
1

2
1 vote, 10.0%
3
1 vote, 10.0%
4
7 votes, 70.0%
5
I really enjoyed writing about 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. Since then the I have received question that how to copy data as well along with schema. The answer to this is Database Publishing Wizard. This wizard is very flexible and works with modes like schema only, data only or both. It generates a single SQL script file which can be used to recreate the contents of a database by manually executing the script on a target server.

The pre-requisite for Database Publishing Wizard is .NET 2.0 Framework, SQL Server 2005 Management Objects, SMO. The Database Publishing Wizard will script all objects that the supplied User has permissions to see in the source database. Any objects created "WITH ENCRYPTION" cannot be scripted. If such objects exist in the source database, the tool will not produce a script.

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\

Now login using 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.

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

Command windows will generate output of action it is taking. See below two screen shots of it.





If you have followed this tutorial exactly you will end up with adventurework.sql which will be quite big and if your computer is not powerful enough it will hang your computer for a while. I suggest that you try this on smaller database of size around 100MB.

Reference : Pinal Dave (http://www.SQLAuthority.com), Database Publishing Wizard

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

pinaldave


Member
Pinalkumar Dave is a Microsoft SQL Server MVP and a prominent expert on SQL servers. He has written over 1100 articles on the subject on his blog at http://blog.sqlauthority.com. He is a dynamic and proficient Principal Database Architect, Corporate Trainer and Project Manager, who specializes in SQL Server Programming and has 7 years of hands-on experience. He holds a Masters of Science degree and a number of certifications, including MCDBA and MCAD (.NET). He was awarded Regional Mentor for PASS Asia and is also Mentor for Solid Quality India.
Occupation: Founder
Company: http://blog.SQLAuthority.com
Location: India India

Other popular Database articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
GeneralGood Article Pinmembercdbh7:00 19 Nov '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 17 Nov 2007
Editor:
Copyright 2007 by pinaldave
Everything else Copyright © CodeProject, 1999-2009
Web16 | Advertise on the Code Project