Thursday, February 9, 2012

Default Location for Backup & Restore database in SQL Server

"Hello World, "
Off course, even if we start writing or printing a program, the first output program we write is printf "Hello World".
So, here i go with the same trend.
This is my first blog publish .. I have been answering questions and doubts in many forums and blogs.., i thought, its time i start writing blogs and publish articles at my own blogspot. so, here we go..

Off lately, I have been interviewing candidates for a DBA position in our company. What i could infer from the answers is that, they fail to understand the basics of how SQL Server engine works.
First and the foremost issue i would like to discuss here is that, 
If there's a backup database command issued in the management studio / Query Analyzer without providing the appropriate backup location. what is the output ?

For Ex :- 
Backup database <database name> to disk = 'databasename_date_time.bak' 
what happens ??
Obviously, we have a common answer that the query returns error asking to provide a proper location. 
WRONG !!





This query works absolutely fine and the database will be backed up accordingly. 
Now, where will the database backup be residing ? how will it be backed up ? how can we check about the backup location ?

There's a default location mentioned for every database while installing. As, the other folders are created like the Data, log and Binn, SQL Server creates a folder called Backup in the root directory.


we can check the root directory location here :- 
Right click on the Database Instance > Properties. Under the General properties you have the Root Directory.
If we check in this location, we can find a folder called Backup to which the database file will be backed up.


Even while restoring the database, if we issue a command without providing the appropriate location. what does the SQL Server do ?

It restores the database successfully. Again, when the restore command is issued.. First, it checks if there's any location provided in the query, if not, SQL Server tries to find the backup file in the default location 


"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup"  to restore the database accordingly.


You must have noticed. if you use the GUI to restore any database and when you click on the browse button to navigate to the backup file path. First, it takes you to the default location and then lets you choose the proper location.

There's a lot more to come along the way.


-Cheers

No comments:

Post a Comment

Multiple Linear Regression

Multiple Linear Regression is a process that uses multiple explanatory variables to predict the outcome of a response variable . The pu...