Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
Changes the default database for a 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
sp_defaultdb
[ @loginame = ] N'loginame'
, [ @defdb = ] N'defdb'
[ ; ]
The login name. @loginame is sysname, with no default. @loginame can be an existing SQL Server login or a Windows user or group. If a login for the Windows user or group doesn't exist in SQL Server, it's automatically added.
The name of the new default database. @defdb is sysname, with no default. @defdb must already exist.
0
(success) or 1
(failure).
sp_defaultdb
calls ALTER LOGIN
, which supports extra options. For information about changing default database, see ALTER LOGIN.
sp_defaultdb
can't be executed within a user-defined transaction.
Requires ALTER ANY LOGIN
permission.
The following example sets AdventureWorks2022
as the default database for SQL Server login Victoria
.
EXEC sp_defaultdb 'Victoria', 'AdventureWorks2022';
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register today