I have a a SQL script that creates a database, and want to know how to run this from a batch file at a command prompt. Do I create a batch file with a few lines of code pointing to the location of the .sql
file, or create a new batch file containing the contents of the .sql
file?
2条答案
按热度按时间cetgtptt1#
You could create a batch file and use the -i flag with sqlcmd.exe, where -i sets the path to the .sql file you want to run:
See http://msdn.microsoft.com/en-us/library/ms162773.aspx for a full list of the flags and this post, How to use sqlcmd to create a database .
ebdffaop2#
is quite easy, you only need 3 things:
SQL Client Path/ Script Path/ SQL Conection data/
Then you can run it directly from the batch without any complex script - let me know if you have the info I can arrange it.
regards