Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy entire database contents (schema and data)

I need to copy the contents (tables, views, procs, DATA, etc.) of a SQL Server database and copy it to another SQL Server database. I need to do this entirely in a script as I am not able to carry over files to the destination web server. Using Microsoft SQL Server Management Studio, how can I accomplish this?

Note: The database I am copying to will have the same name and be completely empty.

like image 623
Brian David Berman Avatar asked Dec 15 '10 01:12

Brian David Berman


People also ask

How do I copy an entire database?

On either the source or destination SQL Server instance, launch the Copy Database Wizard in SQL Server Management Studio from Object Explorer and expand Databases. Then right-click a database, point to Tasks, and then select Copy Database.

Can we copy schema from one database to another?

Use the db2move utility with the -co COPY action to copy a single schema or multiple schemas from a source database to a target database. Most database objects from the source schema are copied to the target database under the new schema.

How do I copy a table structure and data in SQL?

If you want to copy the data of one SQL table into another SQL table in the same SQL server, then it is possible by using the SELECT INTO statement in SQL. The SELECT INTO statement in Structured Query Language copies the content from one existing table into the new table.


2 Answers

You can script the database schema and data using SSMS

Right click on the database. Choose tasks....then choose generate sql scripts.

Specify all objects. Then in the options menu choose at the bottom to generate scripts for data.

Below are some links that will be helpful

http://blog.sqlauthority.com/2007/08/21/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/

http://blog.sqlauthority.com/2007/11/16/sql-server-2005-generate-script-with-data-from-database-database-publishing-wizard/

like image 93
John Hartsock Avatar answered Sep 22 '22 18:09

John Hartsock


You can backup the database and restore to any instance you'd like. Since I don't like posting the "how to" when I learned it someplace else originally - here's the MSDN describing the process.

http://msdn.microsoft.com/en-us/library/ms187048.aspx

It is how we do things in our production environment. We back up and restore to our other instances.

like image 23
iivel Avatar answered Sep 23 '22 18:09

iivel