更新时间:2021-12-04 23:15:14
sp_defaultdb 的替代方案(其中 将在 Microsoft SQL Server 的未来版本中删除) 可能是 ALTER LOGIN
:
Alternative to sp_defaultdb (which will be removed in a future version of Microsoft SQL Server) could be ALTER LOGIN
:
ALTER LOGIN [my_user_name] WITH DEFAULT_DATABASE = [new_default_database]
注意:与 sp_defaultdb
解决方案不同,用户和数据库名称不带引号.如果名称有特殊字符,则需要括号(最常见的例子是域用户,它是 domain\username
,没有括号就不能工作).
Note: unlike the sp_defaultdb
solution user and database names are provided without quotes. Brackets are needed if name had special chars (most common example will be domain user which is domain\username
and won't work without brackets).