SQL Server 单用户模式维护

在服务器升级、系统数据库报错无法启动的场景中会使用到 “单用户” 模式启动MSSQL以进行维护管理。

相应的步骤如下: 

1、进入单用户模式:

(需要进入 MSSQLBINN 目录) sqlservr.exe -sMSSQLSERVER -c -f -m

 sqlservr --参数说明
  [-c] (not as a service) -->不以service启动(关闭CMD后MSSQL服务会关闭)
  [-d file] (alternative master data file)
  [-l file] (alternative master log file)
  [-e file] (alternate errorlog file)
  [-f] (minimal configuration mode) -->最小配置模式启动(加快启动)
  [-m] (single user admin mode) -->单用户模式
  [-g number] (stack MB to reserve)
  [-n] (do not use event logging)
  [-s name] (alternate registry key name)
  [-T <number>] (trace flag turned on at startup) -->启动相应的TRACEID号(常用 TRACE flag 有)
  [-x] (no statistics tracking)
  [-y number] (stack dump on this error)
  [-B] (breakpoint on error (used with -y))
  [-K] (force regeneration of service master key (if exists))

2、启动MSSQL 后使用 sqlcmd 命令登录

用法: Sqlcmd               [-U 登录 ID]         [-P 密码]
  [-S 服务器]              [-H 主机名]          [-E 可信连接]
  [-d 使用数据库名称]      [-l 登录超时值]      [-t 查询超时值]
  [-h 标题]                [-s 列分隔符]        [-w 屏幕宽度]
  [-a 数据包大小]          [-e 回显输入]        [-I 允许带引号的标识符
  [-c 命令结束]            [-L[c] 列出服务器    [清除输出]]
  [-q "命令行查询"]        [-Q "命令行查询" 并退出]
  [-m 错误级别]            [-V 严重级别]        [-W 删除尾随空格]
  [-u unicode 输出]        [-r[0|1] 发送到 stderr 的消息]
  [-i 输入文件]            [-o 输出文件]        [-z 新密码]
  [-f <代码页> | i:<代码页>[,o:<代码页>]]       [-Z 新建密码并退出]
  [-k[1|2] 删除[替换]控制字符]
  [-y 可变长度类型显示宽度]
  [-Y 固定长度类型显示宽度]
  [-p[1] 打印统计信息[冒号格式]]
  [-R 使用客户端区域设置]
  [-b 出错时中止批处理]
  [-v 变量 = "值"...]  [-A 专用管理连接]
  [-X[1] 禁用命令、启动脚本、环境变量[并退出]]
  [-x 禁用变量情况]

  [-? 显示语法摘要] 

3、在sqlcmd命令下使用正常的SQL命令(执行一条语句需要输入  GO ) 

原文地址:https://www.cnblogs.com/loudon/p/3628008.html