博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
sqlcmd
阅读量:6956 次
发布时间:2019-06-27

本文共 2451 字,大约阅读时间需要 8 分钟。

C:\Users\clu>sqlcmd -?

Microsoft (R) SQL Server Command Line Tool
Version 11.0.2100.60 NT x64
Copyright (c) 2012 Microsoft. All rights reserved.

usage: Sqlcmd [-U login id] [-P password]

[-S server] [-H hostname] [-E trusted connection]
[-N Encrypt Connection][-C Trust Server Certificate]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w screen width]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-c cmdend] [-L[c] list servers[clean output]]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-m errorlevel] [-V severitylevel] [-W remove trailing spaces]
[-u unicode output] [-r[0|1] msgs to stderr]
[-i inputfile] [-o outputfile] [-z new password]
[-f <codepage> | i:<codepage>[,o:<codepage>]] [-Z new password and exit]
[-k[1|2] remove[replace] control characters]
[-y variable length type display width]
[-Y fixed length type display width]
[-p[1] print statistics[colon format]]
[-R use client regional setting]
[-K application intent]
[-M multisubnet failover]
[-b On error batch abort]
[-v var = "value"...] [-A dedicated admin connection]
[-X[1] disable commands, startup script, environment variables [and exit]]
[-x disable variable substitution]
[-? show syntax summary]

 

Another approach would be to create a .BAT file with the following command:

for %%G in (*.sql) do sqlcmd /S servername /d databaseName -E -i"%%G" pause

Place this .BAT file in the directory from which you want the .SQL files to be executed, double click the .BAT file and you are done!

 

参数说明

-S [protocol:]server[instance_name][,port]
-d db_name
-E (use trusted connection)
-i input_file
-U login_id
-P password

错误1

Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.. 

错误2

加上用户名和密码后提示

Sqlcmd: The -E and the -U/-P options are mutually exclusive.  互斥的

 修正

添加-U和-P,并且去掉-E就可以执行

输出到文件

 

 

脚本文件

(1).没有任何参数的for格式为:for %%i in (set) do command%%i 为变量set为一个文件或者一组文件,其实就是一个集合。可用通配符,比如*.txt。command 是要执行的命令。看个例子: 当前目录中有如下文件: a.txt b.mp3 c.mp3 c.wma a.rm e.bat你想显示里面的扩展名为mp3的文件,你会用什么命令呢?当然是dir了,dir *.mp3。 同样的,for也可以来实现,如下: for %%i in (*.mp3) do echo %%i 这如何理解? for会先从括号里面执行,因为括号里面是*.mp3,所以for会先得到当前目录下所有的扩展名是mp3的文件,并把它们作为一个集合,而每个文件名就是一个元素, 像这样{b.mp3,c.mp3},然后用%%i依次代替每个元素,之后做do后面的命令。当然,()里面不局限于一个文件或者通配符,可以有多个,比如:for %%i in (*.mp3,*.wma) do echo %%i   也是可以的。注意:do 后面可以跟任何命令,不要局限于echo,这里只是演示。

>清空文件,再写入

>>追加

脚本的注释::

 

 

转载地址:http://dsmil.baihongyu.com/

你可能感兴趣的文章
C# 使用接口进行排序
查看>>
干货!APP推广全周期解决方案 只需做好这6步
查看>>
存储基础网络面临的几大问题
查看>>
高效|五大模式和两大创新,看懂智能制造具体呈现
查看>>
LNMP动态网站部署架构 Linux + Nginx 配置Nginx服务
查看>>
cai
查看>>
电力变压器胶模时要注意到哪几点问题?中港扬盛提醒
查看>>
Linux 高可用(HA)集群之keepalived详解
查看>>
parse AST with Clang-example
查看>>
面向切面编程(AOP模式)
查看>>
学java就两个问题
查看>>
asdasdas da
查看>>
文本三剑客grep、sed、awk
查看>>
双机热备软件
查看>>
https提供安全的web通讯
查看>>
Spark图处理GraphX学习笔记!
查看>>
强制Apache Web服务器始终使用https
查看>>
四、openstack安装之Nova篇
查看>>
关于电脑无法开机或无法启动的几种可能和解决方案
查看>>
Jewel版本Ceph集群功能性能测试
查看>>