C# .NET - database backup - Asked By Trisha on 23-Feb-11 11:13 AM

i want to give database backup option to my customer... could you Please tell me how to do that???
raj kumar's replied to Trisha on 23-Feb-11 11:23 AM
Make a Backup Copy - Now we want to make an exact copy of the data in our "table1" table.

We use the following SQL statement:

SELECT * INTO table1_Backup FROM table1

We can also use the IN clause to copy the table into another database:

SELECT * INTO table1_Backup IN 'Backup.mdb' FROM table1


you can just pass this sql statement in your form (Sqlcommand)

             thank you

Mohan Raj Aryal replied to Trisha on 23-Feb-11 11:38 AM
I would normally create a Schedule/Job for Database backup. You can refer http://support.microsoft.com/kb/930615 in Microsoft support site. 

The T-SQL you use to create database backup is: 

BACKUP DATABASE { database_name | @database_name_var } 
TO <backup_device> [ ,...n ] 
[ <MIRROR TO clause> ] [ next-mirror-to ]
[ WITH { DIFFERENTIAL | <general_WITH_options> [ ,...n ] } ]

For more details refer to: http://msdn.microsoft.com/en-us/library/ms186865.aspx in MSDN.
For e.g. to keep backup on C:\Backup\ directory you can use below statement
BACKUP DATABASE 'YourDataBase' TO DISK = @'C:\Backup\YourDataBase' + '_' + CONVERT(VARCHAR(20),GETDATE(),112) + '.BAK' 

Also you can provide all database backup using master database by selecting records from master.dbo.sysdatabases and using cursor. Here is an http://www.mssqltips.com/tip.asp?tip=1070. 
Priyanka replied to raj kumar's on 23-Feb-11 11:51 AM
sir i dont want to create backup of one table .. i want to create bacup of whole database on the location of my choice...