标题: [网络工具] 两个SQLCMD 用于连接SQLserver和执行SQL [打印本页]
作者: 依山居 时间: 2015-10-18 00:32 标题: 两个SQLCMD 用于连接SQLserver和执行SQL
AnalogX SQLCMD
http://www.analogx.com/contents/ ... d/Documentation.htm- nalogX SQLCMD allows you to quickly and easily run SQL queries against ODBC data sources. Basically, it's a simple portable way to execute SQL commands from batch files, etc.
-
- SQLCMD is like most command line utilities out there; from the command prompt you can type the name by itself to get a list of options:
-
- F:\tools\sqlcmd> sqlcmd
-
- AnalogX SQLCMD version 1.00 (Release)
- The latest version can always be found at http://www.analogx.com/
-
- Usage: SQLCMD [options]
- Options: /USER [name] Username to login as
- /PASS [password] Password for username
- /DB [database] Name of ODBC connection to use
- /LOG [filename] Log results to file
- /APPEND Append results to file
- /SILENT Do not decode results
- /COMMAND [cmd] SQL command to execute
-
- Here's a brief description of each option:
- USER This is the username to login to the database with. This field
- is optional and will try to log in using a NULL account when it
- is not supplied.
- PASS Password for username specified above.
- DB ODBC Database to connect to.
- LOG Specify the filename to log to. Useful for debugging or keeping
- track of operations performed. While not a log in the normal
- sense, it outputs all information pertaining to commands run.
- APPEND Instead of overwriting the existing log file, it will append
- onto it.
- SILENT Suppresses all text output.
- COMMAND SQL query to perform
-
- It's all pretty straight-forward (to my thinking, at least). Here's a couple of examples:
-
- sqlcmd /log "C:\Logs\sqlcmd.log" /append /db "Website" /command "select * from [users]"
-
- or:
-
- sqlcmd /user Jimmy /pass Password /db "Website" /command "update [users] set Downloads=1"
-
- also, if you execute it like so:
-
- sqlcmd /user Han /db "Website"
-
- without the /COMMAND then it will go into it's "interactive" mode, where you can just enter in SQL queries. Once in this mode, simply type 'QUIT' and it will exit.
-
- If the program thinks it has successfully executed the command, it will return 0, otherwise it will return 1 (these are normally the defaults for success and failure for command line programs), so it should be easy to include SQL commands into batch files.
复制代码
作者: 依山居 时间: 2015-10-18 00:51
另一个是SQL SERVER中自带的SQLCMD
https://msdn.microsoft.com/en-us/library/ms162773(v=sql.130).aspx
还有OSQL
https://msdn.microsoft.com/en-us/library/ms162806.aspx
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |