sp_defaultdb (Transact-SQL)
Applies to: SQL Server
Changes the default database for a Microsoft SQL Server login.
Important
This feature will be removed in a future version of SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use ALTER LOGIN instead.
Transact-SQL syntax conventions
Syntax
sp_defaultdb [ @loginame = ] 'login', [ @defdb = ] 'database'
Arguments
[ @loginame = ] 'login'
Is the login name. login is sysname, with no default. login can be an existing SQL Server login or a Windows user or group. If a login for the Windows user or group does not exist in SQL Server, it is automatically added.
[ @defdb = ] 'database'
Is the name of the new default database. database is sysname, with no default. database must already exist.
Return Code Values
0 (success) or 1 (failure)
Remarks
sp_defaultdb calls ALTER LOGIN. This statement supports additional options. For information about changing default database, see ALTER LOGIN (Transact-SQL).
sp_defaultdb cannot be executed within a user-defined transaction.
Permissions
Requires ALTER ANY LOGIN permission.
Examples
The following example sets AdventureWorks2022 as the default database for SQL Server login Victoria
.
EXEC sp_defaultdb 'Victoria', 'AdventureWorks2022';
See Also
Security Stored Procedures (Transact-SQL)
ALTER LOGIN (Transact-SQL)
sp_addlogin (Transact-SQL)
sp_droplogin (Transact-SQL)
sp_grantdbaccess (Transact-SQL)
System Stored Procedures (Transact-SQL)
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho