|
需求:在一台服务器导出了一张表的结构和数据导入到另外一台服务器,源数据库导出的 .sql 文件非常大,占用有 1G 多,如果使用 SSMS 新建查询的方式运行将无法正常打开,程序会卡死,如何运行非常大的 SQL 脚本呢?
可以使用 SQLCMD 工具执行 .sql 脚本文件,参数如下:
sqlcmd
-a packet_size
-A (dedicated administrator connection)
-b (terminate batch job if there is an error)
-c batch_terminator
-C (trust the server certificate)
-d db_name
-D
-e (echo input)
-E (use trusted connection)
-f codepage | i:codepage[,o:codepage] | o:codepage[,i:codepage]
-g (enable column encryption)
-G (use Azure Active Directory for authentication)
-h rows_per_header
-H workstation_name
-i input_file
-I (enable quoted identifiers)
-j (Print raw error messages)
-k[1 | 2] (remove or replace control characters)
-K application_intent
-l login_timeout
-L[c] (list servers, optional clean output)
-m error_level
-M multisubnet_failover
-N (encrypt connection)
-o output_file
-p[1] (print statistics, optional colon format)
-P password
-q "cmdline query"
-Q "cmdline query" (and exit)
-r[0 | 1] (msgs to stderr)
-R (use client regional settings)
-s col_separator
-S [protocol:]server[instance_name][,port]
-t query_timeout
-u (unicode output file)
-U login_id
-v var = "value"
-V error_severity_level
-w screen_width
-W (remove trailing spaces)
-x (disable variable substitution)
-X[1] (disable commands, startup script, environment variables, optional exit)
-y variable_length_type_display_width
-Y fixed_length_type_display_width
-z new_password
-Z new_password (and exit)
-? (usage)
执行 sqlcmd 命令如下:
go-sqlcmd 实用工具
使用 go-sqlcmd 实用工具(预览版),可以在命令提示符下输入 Transact-SQL 语句、系统过程和脚本文件,并使用适用于 Go 语言的 go-mssqldb 驱动程序。 go-sqlcmd 旨在将 sqlcmd 完整地移植到 Go 语言,并编译成可执行的二进制文件,用于 Windows、macOS 和 Linux 的 x64 和 arm64 体系结构。 下载并安装 go-sqlcmd 二进制文件,无需其他依赖项即可开始使用。 使用 go-sqlcmd(而不是 sqlcmd)会移除 ODBC 驱动程序依赖项,为 Azure Active Directory 身份验证类型增加选项,并添加其他增强功能。
参考:
https://learn.microsoft.com/zh-cn/sql/tools/sqlcmd/sqlcmd-utility?view=sql-server-ver16
https://learn.microsoft.com/zh-cn/sql/tools/sqlcmd/go-sqlcmd-utility?view=sql-server-ver16
|
上一篇:VMware(VM)虚拟机链接克隆和完整克隆区别下一篇:.NET Core 类库读取版本和嵌入的资源
|