单击“确定”。此时,我们已经将数据库文件从该计算机中分离出来。
导入数据库
可以分离,也可以重新引入。
在对象资源管理器中右键单击数据库,然后单击附加。
在弹出的对话框中选择“添加”按钮,并选择数据库文件(用。mdf后缀)添加。
例如,我的是ForStudy.mdf,然后单击确定。
提示:
使用sqlcmd修改sa密码:
在CMD下输入(原密码为123456,新密码为I2e456)
Sqlcmd实用工具
可以在命令提示符下、在SQLCMD模式下的查询编辑器中、在Windows脚本文件中或在SQL Server代理作业的操作系统(Cmd.exe)作业步骤中输入Transact-SQL语句、系统过程和脚本文件。
重要解释
在查询编辑器的普通模式和SQLCMD模式下,SQL Server Management Studio使用Microsoft。NET Framework sqlclient执行批处理。
从命令行运行sqlcmd时,sqlcmd使用ODBC驱动程序。因为可以应用不同的默认选项,
因此,在SQL Server Management Studio sqlcmd模式和SQLCMD实用工具中执行相同的查询时,您可能会看到不同的行为。
目前,sqlcmd不要求命令行选项和值之间有空格。但是,在未来版本中,命令行选项和值之间可能需要空格。
语法
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
-e (echo input)
-E (use trusted connection)
-f codepage | i:codepage[,o:codepage] | o:codepage[,i:codepage]
-h rows_per_header
-H workstation_name
-i input_file
-I (enable quoted identifiers)
-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 column_width
-W (remove trailing spaces)
-x (disable variable substitution)
-X[1] (disable commands, startup script, environment variables and optional exit)
-y variable_length_type_display_width
-Y fixed_length_type_display_width
-z new_password
-Z new_password (and exit)
-? (usage)