1.SQL SERVER
SQLCMD的用法,使用CMD 执行sql语句
语法如下:
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
通过bat脚本执行
echo "开始执行" sqlcmd -S 10.32.1.86 -d SysMonitor -U sysmonitor -P **** -Q "select * from tUser" echo "结束执行" pause