1.) Executing a sql file with SQLCMD command and passing a variable value to file variable.
Let's say restoredb.sql is a file contains following sql.
Let's say restoredb.sql is a file contains following sql.
RESTORE
DATABASE MyDB FROMDISK = '$(root)\mydb.bak'WITH REPLACE,MOVE 'mydb_data' to '$(root)\mydb.mdf',GO
Now I can execute the content of restoredb.sql file with any value of root variable.
sqlcmd -E -i restoredb.sql -v root="%CD%"
Site Reference:
No comments:
Post a Comment