SQLCMD的用法,使用CMD 执行sql语句
SQLCMD 允许在Windows命令窗中通过命令行提示符运行脚本.
语法如下:
sqlcmd
[
{ { -U <login id> [ -P <password> ] } | -E }
]
[-S <server> [ \<instance > ] ] [ -H <workstation> ] [ -d <database> ]
[ -l <time out> ] [ -t <time out> ] [ -h <headers> ]
[ -s <col separator> ] [ -w <col width> ] [ -a <packet size> ]
[ -e ] [ -I ]
[ -c <cmd end> ] [ -L [ c ] ] [ -q "<query>" ] [ -Q "<query>" ]
[ -m <error level> ] [ -V ] [ -W ] [ -u ] [ -r [ 0 | 1 ] ]
[ -i <input file> ] [ -o <output file> ]
[ -f <codepage> | i:<codepage> [ <, o: <codepage> ]
[ -k [ 1 | 2 ] ]
[ -y <display width> ] [-Y <display width> ]
[ -p [ 1 ] ] [ -R ] [ -b ] [ -v ] [ -A ] [ -X [ 1 ] ] [ -x ]
[ -? ]
]
SQLCMD -Usa -Pmypassword -Q "SELECT * FROM databasename..tablename"
其中-Q大写和-q小写是由区别的,都会执行查询,但是前者在完成查询的时候会退出SQLCMD,而后者不会。
执行sql脚本:
D:\install>sqlcmd -Usa -P123456 -i testsql.sql