Search code examples
c#asp.netsqlsqlcmddatabase-backups

Can the same sqlcmd.exe used for any db back up


We are using sqlcmd.exe to back up our database programatically. So while i am checking the path of exe it is placed inside "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE"

So my doubt is can the same sqlcmd.exe used to take db backup from sql server 2005 and 2008, or to take back up of 2005 whether we have to use different sqlcmd?


Solution

  • The sqlcmd utility in SQL Server lets you run Transact-SQL statements and related commands at a command prompt, within a script file or in a Query Editor window in SQL Server Management Studio. It can be a handy tool, whether you want to run simple ad hoc queries or create script files to perform routine tasks or automate procedures. Although the utility supports a number of advanced options, you can start using sqlcmd with relative ease by entering simple commands at the Command Prompt window on any system where SQL Server is installed.

    Interactive mode in sqlcmd To quickly get started using sqlcmd you can enter interactive mode. Interactive mode lets you run Transact-SQL statements and sqlcmd commands directly, similar to entering statements in a Query Editor.

    Syntax to take backup:

    sqlcmd -S.\SQLExpress -Q"BACKUP DATABASE dbName  TO DISK = 'path'"
    

    The path you have mentioned in the post is correct. It can vary version to version of sql server.

    You can use the sqlcmd of sqlserver 2005 to take backup of sql server 2008.