Thursday, August 18, 2011

BACKUP AND RESTORE A DATABASE

The following are the steps for backup and restoring a database.

BACKUP A DATABASE:
Step: 1 Take a database you want to make a backup. Suppose the name is Example.dbo
Step: 2 Right click on the Example database go to tasks go to backup source is the same Example. In the destination, remove the already selected destination. Then click add click browse. Type the file name you need to make as a backup file. Suppose ExampleBackUp.bak is my backup file. .bak is must.
Step: 3 Click ok then ok then ok. If everything is fine, you will be seen a message like database Example is successfully restored.
Step: 4 Now there is a backup for your database Example.dbo

RESTORE A DATABASE:
Now if you need to restore the database for which you have took a backup. The following steps needed to be followed.
Step: 1 Right click on databases, click restore database.
Step: 2 Type the database name you need to be restored as Example in the destination. On the source, click from device then browse click add. Then in the backup list, you will be made visible with the name with which you have taken the backup of your database. In this example, I have taken my database name as ExampleBackUp.bak it is visible in the list. Click that. Click ok. Again click ok.
Step: 3 Now, in the Select the backup sets to restore, tick the Restore check box.
Step: 4 Finally, click ok.
Now click refresh. Expand the databases, you can find your database along with your tables.

Wednesday, August 17, 2011

Difference between TRUNCATE and DELETE commands

1>TRUNCATE is a DDL command whereas DELETE is a DML command.

2>TRUNCATE is much faster than DELETE.

Reason:When you type DELETE.all the data get copied into the Rollback Tablespace first.then delete operation get performed.Thatswhy when you type ROLLBACK after deleting a table ,you can get back the data(The system get it for you from the Rollback Tablespace).All this process take time.But when you type TRUNCATE,it removes data directly without copying it into the Rollback Tablespace.Thatswhy TRUNCATE is faster.Once you Truncate you cann't get back the data.

3>You cann't rollback in TRUNCATE but in DELETE you can rollback.TRUNCATE removes the record permanently.

4>In case of TRUNCATE ,Trigger doesn't get fired.But in DML commands like DELETE .Trigger get fired.

5>You cann't use conditions(WHERE clause) in TRUNCATE.But in DELETE you can write conditions using WHERE clause