Friday, August 25, 2006

How to create a database with previous data from a backup file(.bak)?

Situation: U have only a backup file of a database abcdatabase with extension of .bak (abcdatabase.bak), and u want to create a database called abcdatabase with the data with are in bak files.


Things to remember :
Database Name : abcdatabase
Backupfile Name : abcdatabase.bak
SQL SERVER NAME: your system name is it is local (EG: PRINCEPY)

Step 1: open command prompt
Step 2: create a blank database with a name"abcdatabase", and close query analyser and sql manager etc.
Step 3: navigate to "C:\Program Files\Microsoft SQL Server\MSSQL\Binn>"
Step 4: use "osql" type "osql /?" for help
SYNTAX : > osql [-U login id] [-P password] [-H hostname]
EQ : > osql -U sa -P -H PRINCEPY
Step 5: you will ge "1>" in cmd, type the following
1> RESTORE DATABASE abcdatabase FROM DISK='c:\abcdatabase.bak'
2> GO
Step 6: After sucessfull creatio type EXIT