5

I am using windows7 os and i have a database on MSSQL server 2005 i am using following codes to import database

sqlcmd -S [server instance name] -d [database name] -i [filename you want to import]

i want to export database something like above command if any?

jayakrishnan
  • 51
  • 1
  • 1
  • 2

2 Answers2

3

Assuming you've the right permissions, try:

SqlCmd -E -S Server_Name –Q "BACKUP DATABASE [Name_of_Database] TO DISK=’X:PathToBackupLocation[Name_of_Database].bak'"

Note: Instead of -E, you can use -U and -P to specify user credentials.

Then to restore, use the following syntax:

SqlCmd -E -S Server_Name –Q "RESTORE DATABASE [Name_of_Database] FROM DISK=’X:PathToBackupFile[File_Name].bak'"

Source: Backup and Restore Your SQL Server Database from the Command Line.

To export specific data, see: How to export data as CSV format from SQL Server using sqlcmd?

kaiser
  • 1,251
  • 1
  • 16
  • 24
kenorb
  • 5,943
  • 1
  • 44
  • 53
2

The -i is to import a procedure/table/whatever from a file and there is a -o option to output a table/procedure to a file. See sqlcmd.

Omnius
  • 21
  • 2