Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Tuesday, 4 August 2015

SQL Database Backup using SQL commands



New, Let's see how we can take backup by using SQL commands.

SQLCMD is used to connect to SQL Server management studio from command prompt.

OSQL is used to connect to SQL Server management studio from command prompt below SQL Server 2005 version.

You can use windows .batch file to schedule the job daily to backup the database.

Below is the simple command which can be use to backup the database from consol after connecting to the SQL Server:-

BACKUP DATABASE TEST TO DISK='F:\Chanchal\Sql_Database_Backup\TEST_DB.BAK';

GO

Note:-  You would always need to type GO keyword otherwise your query won't get executed.

Below is the command which can be used before connecting to the SQL Server database:-

SQLCMD -E -S TEST_SERVER –Q "BACKUP DATABASE TEST TO DISK=’F:\CHANCHAL\SQL_DATABASE_BACKUP.BAK'"

Below is the screen shot for above command:-

 Above command can be schedule in windows bat file and can be call on particular time so the automatic backup happens.


By using above commands you can backup your database on MEDIA as well.


No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.