onkami
onkami

Reputation: 9411

Create batch file to copy contents of one SQL Server database to another

I need to create a batch file (script) to copy entire content of one SQL Server database to another. Source database is local for the machine. What command line tools and commands therein I could use? Destination database can be dropped entirely.

Also, I need to run a pair of SQL queries afterwards, also from batch file.

Thanks in advance!

Upvotes: 1

Views: 3528

Answers (2)

kleinohad
kleinohad

Reputation: 5912

you can read about Run Transact-SQL Script Files Using sqlcmd from here: http://msdn.microsoft.com/en-us/library/ms170572.aspx

Upvotes: 1

NEO
NEO

Reputation: 213

first u need to create your sql queries then u can use this command to run it via batch file

sqlcmd -S %computername%\%SName% -U %UName% -P %Pwd%  -i SQL_DB.sql >> _Deploy.txt 2>&1

this command gets computer name and sqlserver instance name and user name and password and run SQL_DB.sql file near batch file that contains our queries and save the result in a text file named _deploy.txt

Upvotes: 1

Related Questions