GurdeepS
GurdeepS

Reputation: 67223

Copy database to another on same server

I have a database and want to copy its tables, etc, to another database, so I can use one of these databases as a "staging" DB.

What is the best/most foolproof way to do this?

Thanks

Upvotes: 0

Views: 3022

Answers (3)

Donny Nyamweya
Donny Nyamweya

Reputation: 21

To be system agnostic... from any commandline:

sqldump -u username -p databasename > backup.sql;
sql -u username -p
<<provide password and access the sql commandline>>
create database newdatabasename;exit;

sql -u username -p newdatabasename < backup.sql

This should build a new database based on a backup of the older one

Upvotes: 1

Gabriel
Gabriel

Reputation: 897

You can just use: Right Click Database -> Tasks -> Copy Database...

Upvotes: 0

Tanner
Tanner

Reputation: 22733

If you want to copy everything, I'd create a full backup of the DB you want to copy: Right click db > Tasks > Backup. Create an new db in SQL server and restore the backup file into it: right click > Tasks> Restore database. This will give you a full copy of the orignal DB.

Upvotes: 0

Related Questions