Table of Contents
MS SQL Server: CREATE LOGIN Command in SQL Server is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.
The CREATE LOGIN command helps create a login account (Login) connecting to SQL Server. The login account will then be mapped to the user account (so before creating the user in SQL Server you must create a login account first).
There are 4 types of login accounts in SQL Server.
- Login account uses Windows Authentication authentication.
- Login account using SQL Server Authentication authentication.
- Account login from certification.
- Account login asymmetric keywords.
Syntax
Create a login account using Windows Authentication authentication
CREATE LOGIN[ten_mienten_dangnhap]FROM WINDOWS[ WITH DEFAULT_DATABASE = ten_cosodulieu| DEFAULT_LANGU| DEFAULT_LANGUAGE = ten_ngonng];
Create a login account using SQL Server Authentication authentication
CREATE LOGIN ten_dangnhapWITH PASSWORD = { 'matkhau' | matkhau_bam HASHED } [ MUST_CHANGE][ , SID = giatri_duynhat| DEFAULT_DATABASE = ten_cosodulieu| DEFAULT_LANGUAGE = ten_ngonngu| CHECK_EXPIRATION = { ON | OFF }| CHECK_POLICY = { ON | OFF }| CREDENTIAL = ten_c| CREDENTIAL = ten_chungthuc];
Create an account login from the certificate
CREATE LOGIN
FROM CERTIFICATE te n_chungnhan;
Create an account asymmetric keyword login
CREATE LOGIN ten_dangnhapFROM ASYMMETRIC KEY ten_khoabatdoixung;
Variable name or variable value
ten_mien
Name of the Windows domain account (Windows domain).
Network basics: Part 6 - Windows Domain
Username
Name of the login account.
ten_cosodulieu
Default database
ten_ngonngu
Default language for login account.
CHECK_EXPIRATION
The default is set to OFF. This option determines the password expiration policy. Must set CHECK_EXPIRATION = ON if using MUST_CHANGE.
matkhau
Password to login account.
matkhau_bam
The hash function value of the login password.
MUST_CHANGE
Used when forcing the password to change after the first login.
giatri_duynhat
The Globally Unique Identifier (GUID) of the login account. If omitted, SQL Server will specify the GUID for the account.
ten_chungthuc
Authentication name of the login account.
ten_chungnhan
Certificate name of the login account.
ten_khoabatdongxung
The name of the asymmetric key of the login account.
Note: See the ALTER LOGIN and DROP LOGIN commands.
Example using Windows Authentication authentication
CREATE LOGIN [test_tenmientipsmake]FROM WINDOWS;
This CREATE LOGIN command will create a new login account [test_tenmienquantrim] and use Windows authentication.
Example using SQL Server Authentication authentication
CREATE LOGIN tipsmakeWITH PASSWORD = 'mk123';
The above CREATE LOGIN command creates the login account TipsMakeusing SQL Server authentication and the password is mk123.
If you want to change the password after the first login, use the command below.
CREATE LOGIN tipsmakeWITH PASSWORD = 'mk123' MUST_CHANGE,CHECK_EXPIRATION= ON;
Note that MUST_CHANGE cannot be used if CHECK_EXPIRATION is OFF. If you turn OFF, it will fail.
Example of using a certificate
CREATE LOGIN TipsMake
FROM CERTIFICATE chungn han1;
FAQ
What should you know about syntax?
Create a login account using Windows Authentication authentication.
What is MS SQL Server: CREATE LOGIN Command in SQL Server?
The CREATE LOGIN command helps create a login account (Login) connecting to SQL Server.
Why is MS SQL Server: CREATE LOGIN Command in SQL Server important?
A clear understanding of MS SQL Server: CREATE LOGIN Command in SQL Server helps you make informed decisions, avoid common mistakes, and use the relevant tools or techniques more effectively.
Reader Comments 0
Sign in with email or Google to join the discussion.