Creates a new SQL Server login that allows a user to connect to an instance of SQL Server by using SQL Server authentication.
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 CREATE LOGIN instead.
When possible, use Windows Authentication.
sp_addlogin [ @loginame = ] 'login' [ , [ @passwd = ] 'password' ] [ , [ @defdb = ] 'database' ] [ , [ @deflanguage = ] 'language' ] [ , [ @sid = ] sid ] [ , [ @encryptopt = ] 'encryption_option' ] [;]
SQL Server logins can contain from 1 to 128 characters, including letters, symbols, and numbers. Logins cannot contain a backslash (\); be a reserved login name, for example sa or public, or already exist; or be NULL or an empty string ('').
If the name of a default database is supplied, you can connect to the specified database without executing the USE statement. However, you cannot use the default database until you are given access to that database by the database owner (by using sp_adduser or sp_addrolemember) or sp_addrole.
The SID number is a GUID that will uniquely identify the login in the server.
Changing the default language of the server does not change the default language of existing logins. To change the default language of the server, use sp_configure.
Using skip_encryption to suppress password hashing is useful if the password is already hashed when the login is added to SQL Server. If the password was hashed by an earlier version of SQL Server, use skip_encryption_old.
sp_addlogin cannot be executed within a user-defined transaction.
The following table shows several stored procedures that are used with sp_addlogin.
A. Creating a SQL Server login
The following example creates a SQL Server login for the user Victoria, with a password of B1r12-36, without specifying a default database.
EXEC sp_addlogin 'Victoria', 'B1r12-36'; GO
B. Creating a SQL Server login that has a default database
The following example creates a SQL Server login for the user Albert, with a password of B5432-3M6 and a default database of corporate.
EXEC sp_addlogin 'Albert', 'B5432-3M6', 'corporate'; GO
C. Creating a SQL Server login that has a different default language
The following example creates a SQL Server login for the user TzTodorov, with a password of 709hLKH7chjfwv, a default database of AdventureWorks2012, and a default language of Bulgarian.
EXEC sp_addlogin 'TzTodorov', '709hLKH7chjfwv', 'AdventureWorks2012', N'български'
D. Creating a SQL Server login that has a specific SID
The following example creates a SQL Server login for the user Michael, with a password of B548bmM%f6, a default database of AdventureWorks2012, a default language of us_english, and a SID of 0x0123456789ABCDEF0123456789ABCDEF.
EXEC sp_addlogin 'Michael', 'B548bmM%f6', 'AdventureWorks2012', 'us_english', 0x0123456789ABCDEF0123456789ABCDEF