copying sqlserver2000 database from one computer to sqlserver 2008 of another computer - sql

i have a database named SAHS in my desktop having sqlserver 2000 installed i want to copy it in my laptop(64bit) having sql server 2008 ..
i tried removing a backup of it..
like this ;
BACKUP DATABASE SAHS
TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\BACKUP\SAHSFullRM.bak'
WITH FORMAT;
GO
can i copy the backup file in my laptop and use the restore statement?.. if yes please show the restore statement im getting error in this :
restore database SAHS
from disk = 'C:...'
saying operating system error.
is there any other simpler way to do so..pls help

Make sure the target server has access to the folder containing the bak file. And on the target server you can try running the Restore Database wizard from SSMS.

i did it myself .Open sqlserver management studio ,from the object explorer expand database column, right click any databse , select task --> restore --> database or Files or Filegroups , restore dialog box opes , write the new name of yor database in To Database , select location and type it in From Device option , select the checkbox , and click on OK ..
ITS DONE .. this is a new feature in sqlserver 2008 ..

Related

How to add a database in SQL Server Management Studio?

I have been sent a database called StudentsDB.mdf and I want to enter it into my SQL Server Management Studio databases . How to do that ?
I want to know if I copy a .mdf file from the directory where are all my databases which is C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA
and sent it to another person will he be able to import this database in his SQL Server Management Studio and see the database?
Try this one
Step 1
Right-click “Databases” and click the “Attach” option to open the Attach Databases dialog box.
Step 2
Click the “Add” button to open the Locate Database Files dialog box.
Step 3
Type in the full name of the .MDF file, including the full device and directory path, as the following example illustrates:
c:\StudentsDB.mdf
Click the "OK" button. SQL Server Management Studio loads the database from the .MDF file.
OR
Step 1
Click “New Query” in the Management Studio’s main toolbar.
Step 2
Type a Create Database statement using the following Transact-SQL code:
CREATE DATABASE MyDatabase ON
(FILENAME = 'c:\StudentsDB.mdf'),
(FILENAME = ' c:\StudentsDB.ldf') FOR ATTACH;
Step 3
Click the “Execute” button in the Transact-SQL toolbar. SQL Server Management Studio restores the database.
OR
CREATE DATABASE StudentDB ON
(FILENAME = N'C:\StudentsDB.mdf')
FOR ATTACH_REBUILD_LOG
GO
Execute the following command from SSMS.
USE master;
GO
EXEC sp_attach_single_file_db #dbname = N'StudentsDB'
,#physname = N'D:\<path to mdf file>\StudentsDB.mdf'
GO
Now if you refresh the database list in SSMS it should show a database StudentsDB in the list.
I want to know if I copy a *.mdf file ... and [send] it to another person, will he be able to import this database?
You can do this, but there are a few considerations. The first is that you need to take the database offline, or use another command to ensure there are no pending transactions waiting to be written or locks or latches waiting to be closed.
The second consideration is that, once the database is imported, you may need to recreate (by hand or by script) a few items that aren't stored within the mdf file itself. This includes users and permissions, links to other databases, and other services that are provided by at the Server level rather than the Database level.

How to copy SQL Server 2008 R2 database from one machine to another

I have a database in SQL Server 2008 R2, and I want to copy this database onto another machine.
How do I make a copy?
And how do I restore it?
Thanks
You can't copy Database to another machine.
Yes you can take back up to same machine and copy it to another machine and do restore.
To take backup follow procedure:
Right Click on the database you want to take backup.
Choose Task -> Back Up.
In Destination, Choose Add.
In File Name click on ... button and choose destination folder where you want to backup with backupname.bak . Click Ok, Ok and Ok. and wait until backup process is completed. Click Ok.
Now copy that backup file into pendrive or any media and paste it to another machine and Open SQL Server 2008 R2
To restore backup follow procedure:
Right Click on the Databases.
Choose Restore Database.
Write database name which you want to restore in To Database field
Select From device radio button in Source for restore. Click on ...
Click on Add button, Select database backup file you have pasted. Click Ok, Ok.
Check the checkbox of Restore in Select the beckup sets to restore.
Go on Options Check Overwrite the existing database & Preserve the replication settings (this fields needed to check only when you try to restore database which is already resided on that another device)
Click Ok. wait until restore complete and click ok.
Tell me if you face any problem.
By Code
To Backup:
USE DATABASE_NAME;
GO
BACKUP DATABASE DATABASE_NAME
TO DISK = 'D:\DATABASE_NAME.Bak'
WITH FORMAT, MEDIANAME = 'D_SQLServerBackups',
NAME = 'Full Backup of DATABASE_NAME';
GO
(If you want to put backup in any folder, the folder must be exist before you take the backup.)
To Restore:
Step 1: Retrive the Logical file name of the database from backup.
RESTORE FILELISTONLY
FROM DISK = 'D:BackUpYourBaackUpFile.bak'
GO
Step 2: Use the values in the LogicalName Column in following Step.
----Make Database to single user Mode
ALTER DATABASE YourDB
SET SINGLE_USER WITH
ROLLBACK IMMEDIATE
----Restore Database
RESTORE DATABASE YourDB
FROM DISK = 'D:BackUpYourBaackUpFile.bak'
WITH MOVE 'YourMDFLogicalName' TO 'D:DataYourMDFFile.mdf',
MOVE 'YourLDFLogicalName' TO 'D:DataYourLDFFile.ldf'
/If there is no error in statement before database will be in multiuser
mode.
If error occurs please execute following command it will convert
database in multi user./
ALTER DATABASE YourDB SET MULTI_USER
GO
There are probably more ways to do this but I usually right-click the database and choose "Tasks → Back up..." with Backup type "Full". After that you can copy the created file to your target machine, connect to its SQL Server in SQL Server Management Studio, right-click the "Databases" folder and choose "Restore Database". Select "Device" and choose the file, then restore.
Another approach would be to script the database in SQL Server Management Studio (right-click the database, then "Tasks → Generate scripts..."). During this process there'll be a step called "Set Scripting Options", where you'll have to click the "Advanced" button and carefully go through the options. You'll definitely want to choose "Data and schema" for the option "Types of data to script". I sometimes prefer this method if I really just want the data structures and the data itself to be transferred.
Update: Sorry, I forgot to mention how to restore the database for the scripting option. I always generate the scripts by selecting "Save to new query window" during the "Set Scripting Options" step. After the script is generated, just leave it there for a moment.
On the target server create a new database with the same name as the one you generated the scripts for. Or you can create a script for that on the source server, too (right-click the database, choose "Script Database as → CREATE TO... → Clipboard") and execute this script by right-clicking the server node in the SSMS Object Explorer, selecting "New query", pasting the script into the query window and executing it. This second option is the better choice if you really need a complete copy of the database and not just the data itself.
Once you've gone down one of these two roads you should have created a new database. Right-click this database in Object Explorer and select "New Query", then copy and paste the script containing the database structure and data into the new query window and execute the query. This should do the trick.
Copying a database using a full database backup will not copy the transactions in the online transaction log.
If this is important, use the following steps to take the database offline, copy the MDF and LDF files, and attach them:
Select the database in SQL Server Management Studio , right-click the database and select Properties. Copy the location of the MDF and LDF files
2.Click OK
3.Right-click the database again, select Tasks, Take offline
4.In Windows Explorer, copy the MDF and LDF files using the location found in step #1
5.Paste them to another location
6.In SQL Server Management Studio right-click the SQL Server instance and select Attach
7.In the next dialog, click Add, find the copied files, select them and click OK
8.Change the default name offered in the Attach AS field. Specify the new name you want for your database here.
9.Click OK
To bring back online the original database, right-click it and select Tasks, Bring online
if you are copying it to a SQL 2008 R2 then all u have to do is
open SQL server management studio
choose your database
right click, go to Tasks --> BackUp
in the database backup window, click add and then give your backup path and file name
click ok
copy the backup file to any drive in the machine to which you want to restore then,
Open SQL server management studio
create a new database
right click on the newly created database, go to Tasks --> Restore --> Database
on the restore window select from device option
add the backup file path
click ok
In addition for copy or move database to another server in same network level you can use SQL Server Copy Database Wizard
for use this method you should
Right click on database
Select task and
Select copy database
Fill source database server login data
Fill destination database server login data
Select transfer method
Select databases to transfer(except system databases)
Extra description about this method
Justin's answer above was almost correct, it is simply right click on database in SSMS and select "Tasks" > "Export Data". This wizard allows you to duplicate the entire database to another location.

SQL Server 2000 backup recovering on SQL Server 2005

I've got a SQL Server database backup (file extension .bak) from an project of 12 y/a which I tried to restore on SQL Server 2005.
But this gave me an error that it was not the right version..
So I'm trying to find a SQL Server 2000 version to see if I can restore it with this but I can't find any version that works.
Is there another program to save my backup?
Copied over from msdn forums:
1) Go to restore database
2) Select the database that you want to back up to
3) Locate the backup file on disk. You may have to put it into the MSSQL Server -> MSSQL.1-> MSSQL -> Backup Folder. It must be a .bak file.
4) Select the back that want to restore from the available backups.
5) Go to the top left "options" property and when you do that select "overrite existing database".
6) Now make sure that the path to the files on database to be restored are correct in this same dialog view. Look at the paths to the database file and the log file and make damn sure that they are the correct ones for the database to be restored. The problem here is that those paths are going to be for the filesystem that the backup came from, not the one you are goning to put the restore onto.
Just to add to that, if you are restoring a database to a new server that does not have the database already in it (to restore to), create a sham database with the same name, then restore to it with the overwrite settings mentioned above.

How do I import a .bak file into Microsoft SQL Server 2012?

Been Googling this for awhile and no answer....can anyone help?
For SQL Server 2008, I would imagine the procedure is similar...?
open SQL Server Management Studio
log in to a SQL Server instance, right click on "Databases", select "Restore Database"
wizard appears, you want "from device" which allows you to select a .bak file
Using the RESTORE DATABASE command most likely. bak is a common extension used for a database backup file. You'll find documentation for this command on MSDN.
Not sure why they removed the option to just right click on the database and restore like you could in SQL Server Management Studio 2008 and earlier, but as mentioned above you can restore from a .BAK file with:
RESTORE DATABASE YourDB FROM DISK = 'D:BackUpYourBaackUpFile.bak' WITH REPLACE
But you will want WITH REPLACE instead of WITH RESTORE if your moving it from one server to another.
.bak is a backup file generated in SQL Server.
Backup files importing means restoring a database, you can restore on a database created in SQL Server 2012 but the backup file should be from SQL Server 2005, 2008, 2008 R2, 2012 database.
You restore database by using following command...
RESTORE DATABASE YourDB FROM DISK = 'D:BackUpYourBaackUpFile.bak' WITH Recovery
You want to learn about how to restore .bak file follow the below link:
http://msdn.microsoft.com/en-us/library/ms186858(v=sql.90).aspx
You can use the following script if you don't wish to use Wizard;
RESTORE DATABASE myDB
FROM DISK = N'C:\BackupDB.bak'
WITH REPLACE,RECOVERY,
MOVE N'HRNET' TO N'C:\MSSQL\Data\myDB.mdf',
MOVE N'HRNET_LOG' TO N'C:\MSSQL\Data\myDB.ldf'

Sql Server 2005 Restore Failing

Running sql server 2005 I have database A. I am trying to restore from a backup of A to database B. I want to retain the database A and create a new testing database B from a previous set of data.
I tried to create B and restore from the .bak AND restore database to B from management studio.
The error is...
TITLE: Microsoft SQL Server Management
Studio
Restore failed for Server
'195448-APP2'.
(Microsoft.SqlServer.Smo)
For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.1399.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Restore+Server&LinkId=20476
------------------------------ ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: The
backup set holds a backup of a
database other than the existing 'B'
database. (Microsoft.SqlServer.Smo)
For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.1399.00&LinkId=20476
------------------------------ BUTTONS:
OK
I found this snippet which I am hesitant to use and want to ask if it would solve my problem of changing the location of the mdf and ldf during the process of restoring the database or does it replace database A's items altogether.
ALTER DATABASE AdventureWorks
SET SINGLE_USER WITH
ROLLBACK IMMEDIATE
RESTORE DATABASE AdventureWorks
FROM DISK = 'C\:BackupAdventureworks.bak'
WITH MOVE 'AdventureWorks_Data' TO 'C:\Data\datafile.mdf',
MOVE 'AdventureWorks_Log' TO 'C:\Data\logfile.ldf',
REPLACE
[http://blog.sqlauthority.com/2007/04/30/sql-server-fix-error-msg-3159-level-16-state-1-line-1-msg-3013-level-16-state-1-line-1/][1]
and for me I would make it...
RESTORE DATABASE B
FROM DISK = 'C:\backupofA.bak'
WITH
MOVE 'B' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\B.mdf',
MOVE 'B_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\B_log.ldf',
REPLACE
What I don't know is if it will affect database A at all. I am hoping the replace refers files associated with B.
or if it should be
RESTORE DATABASE B
FROM DISK = 'C:\backupofA.bak'
WITH
MOVE 'A' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\B.mdf',
MOVE 'A_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\B_log.ldf',
REPLACE
If anyone could help me with the error and/or confirm this fix I would be very grateful as it is not my database I'm playing with.
Thanks.
You could simply use the Copy Database Wizard.
If you wanna do it like pros and use T-SQL the RESTORE .. MOVE ... REPLACE will do what you expected: move the two files at the locations you intend and replace database B with content from the backup. A will be unaffected.
I would use the wizard if I were you: In Sql Server Management Studio right click on "Databases" and select "Restore Database...". This dialog / wizard will do exactly what you are asking - simply select the source .bak file(s) / Database that you want to restore from, enter the name of the database you want to restore to and hit "Ok".
Some notes - if you enter the name of a database that doesnt yet exist (it sounds like this is what you want to do), it will create that database for you. If you enter the name of an existing database it will attempt to restore to that database. If you attempt to restore to an existing database from a backup made of a different database it will fail, however you can force the Sql Server to overwrite the existing database by going to "Options" and checking the "Overwrite the existing database" checkbox.
Also, if you are restoring a backup of an existing database to create a new second copy of that database you may find that the wizard fails as its attempting to create a database using the same database file paths as the ones currently in use by the source database. To fix this you need to click on "Options" and change all of the "Restore As" file paths to files that dont yet exist.
You can also get this wizard to generate an SQL script instead of actually performing the actual restore (click on the "script" button at the top), which is handy if you want learn how to do this sort of thing in raw SQL instead.
It is possible to restore a database from sql server 7, sql server 2000 to sql server 2005.
It can be achieved by using restore and with replace command
use master
restore database mydatabase from disk ='c:\mybackup.bak' with replace
It is easy to take a backup in sql server using this script without any external tools.
Check out Restore with Example.
drop database b first. then do the restore.