Click to Rate and Give Feedback
MSDN
MSDN Library
SQL Server
SQL Server 2012
Database Engine
 sp_defaultdb (Transact-SQL)
Community Content
In this section
Statistics Annotations (0)
Collapse All/Expand All Collapse All
Other versions are also available for the following:
sp_defaultdb (Transact-SQL)

Changes the default database for a Microsoft SQL Server login.

Important note Important

This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use ALTER LOGIN instead.

Topic link icon Transact-SQL Syntax Conventions

          

sp_defaultdb [ @loginame = ] 'login', [ @defdb = ] 'database' 
        
[ @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.

0 (success) or 1 (failure)

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.

Requires ALTER ANY LOGIN permission.

The following example sets AdventureWorks2012 as the default database for SQL Server login Victoria.

EXEC sp_defaultdb 'Victoria', 'AdventureWorks2012';
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker