Backup and Restore Database in SQL Server

this time I will show how to backup database, first I have one database like this :

image

I want to backup database test, just right click on database test choose Task >> Backup.

image

you can choose another Destination folder by Clicking Remove and Add new Destination folder, the highlight text is destination folder of backup file.

image

Note : if you add another destination backup folder, don’t forget to put .bak at the end of filename like this :

image

after that Klik OK :

wait a few second and you will see information message like this :

image

RESTORE DATABASE

now I will delete database tes and try to restore it using backup file, first delete database tes and then create new empty database tes.

image 

as you can see, the database is empty. just right click on database tes and then choose Tasks > Restore > Database :

image

First Choose radio button From device, and point it to your backup destination folder, after that check Restore, and then choose Options properties.

image

then check Overwrite the existing database (WITH REPLACE), after that click OK

image

you will see this information message :

image

USE GENERATE SCRIPTS TO BACKUP DATABASE

this is the second alternative, you can use Generate script to backup database. I will Script database tes, just right click on database then choose Tasks > Generate Scripts, like this :

image

Klik Next :

image

You can Script entire database and all the objects or Select specific database object, in this case I choose Script entire database and all database object, then click Next :

image

You can choose the destination folder of Scripts by changing the File Name, after that click Advanced :

image

in this section, you can change Type of data to script, and I change it to Schema and data. after that click OK, then click Next until Finish

image

RESTORE DATABASE USING SCRIPTS

if you want to restore database using Scripts, just open Script in SQL Server and then execute it by pressing F5

image

success…

image

Create Store Procedure Microsoft SQL Server

this time i will explain how to create store procedure in SQL Server. i used Microsoft SQL Server 2008 R2 as database. first i have created one database and table like this :

image

and this is design of table dbo.tb_profile :

image

now lets create store procedure to insert data into table dbo.tb_profile, right click folde Stored Procedures and choose New Stored Procedure :

image 

after that i write and execute this query:

   1: USE [db_test]

   2: GO

   3: /****** Object:  StoredProcedure [dbo].[sp_InsertData]    Script Date: 02/11/2013 16:28:30 ******/

   4: SET ANSI_NULLS OFF

   5: GO

   6: SET QUOTED_IDENTIFIER ON

   7: GO

   8:  

   9: CREATE PROCEDURE [dbo].[sp_InsertData]

  10:  

  11:     /*Parameter*/

  12:     @id varchar(10),

  13:     @name varchar(25),

  14:     @contact varchar(20)

  15:     

  16: AS

  17: BEGIN

  18:     /*Insert data into Table*/

  19:     insert into tb_profile (id, name, contact)

  20:     values (@id, @name, @contact)

  21: END

after that change CREATE into ALTER like this :

   1: USE [db_test]

   2: GO

   3: /****** Object:  StoredProcedure [dbo].[sp_InsertData]    Script Date: 02/11/2013 16:28:30 ******/

   4: SET ANSI_NULLS OFF

   5: GO

   6: SET QUOTED_IDENTIFIER ON

   7: GO

   8:  

   9: ALTER PROCEDURE [dbo].[sp_InsertData]

  10:  

  11:     /*Parameter*/

  12:     @id varchar(10),

  13:     @name varchar(25),

  14:     @contact varchar(20)

  15:     

  16: AS

  17: BEGIN

  18:     /*Insert data into Table*/

  19:     insert into tb_profile (id, name, contact)

  20:     values (@id, @name, @contact)

  21: END

now lets try our store procedure, open New Query :

image

then i write and execute this Query :

   1: sp_InsertData 'zxc','OKA','080989999'

the result is :

image

success…