|
|
The LOGIN keyword is used to create a login
account based on an existing user account in Microsoft SQL Server.
|
Before creating a login, the person for whom you want to
create the account must have a user account.
The formula to programmatically
create a login is:
CREATE LOGIN loginName { WITH <option_list1> | FROM <sources> }
<option_list1> ::=
PASSWORD = { 'password' | hashed_password HASHED } [ MUST_CHANGE ]
[ , <option_list2> [ ,... ] ]
<option_list2> ::=
SID = sid
| DEFAULT_DATABASE =database
| DEFAULT_LANGUAGE =language
| CHECK_EXPIRATION = { ON | OFF}
| CHECK_POLICY = { ON | OFF}
| CREDENTIAL =credential_name <sources> ::=
WINDOWS [ WITH <windows_options>[ ,... ] ]
| CERTIFICATE certname
| ASYMMETRIC KEY asym_key_name<windows_options> ::=
DEFAULT_DATABASE =database
| DEFAULT_LANGUAGE =language
To let Microsoft SQL Server generate skeleton code for
you, on the Standard toolbar, click New Query to get a text editor. In the
Template Explorer, expand the Login node, drag Create SQL Login Must Change
Password and drop it in the empty text editor:
-- =================================================
-- Create SQL Login Must Change Password template
-- =================================================
CREATE LOGIN <SQL_login_name, sysname, login_name>
WITH PASSWORD = N'<password, sysname, Change_Password>'
MUST_CHANGE,
CHECK_POLICY = <check_policy,ON or OFF, ON>;
GO
After creating a login, a user can use it to connect to
the server. There are many options, as we will see in the next few sections.
To visually create a login in Microsoft SQL Server, in
the Object Explorer, expand the Security node. Right-click Login and click
New Login...

This would display the Login - New dialog box:
