SQL Server database security

Source: Internet
Author: User
-- Create a login user
-- Create login login_name from windows with default_database = database | default_language = language;
Create login [localhost \ hoojo-pc] from windows with default_database = testHome;
-- Create a login user
-- Create login login_name with password = 'pwd' [hashed] [must_change] [check_expiration] [check_policy]
Create login admin with password = '000000', default_database = testHome;

-- View login users
Select * from sys. SQL _logins;

-- Modify a user
Alter login admin with name = jackson;
Alter login jackson with password = 'abc ';

-- Disable and enable users
Alter login jackson disable; -- disable
Alter login jackson enable; -- enable

-- Delete a user
Drop login jackson;

-- Modify the ing credential (map the login name MacraeS to the credential Custodian04)
Alter login jackson with credential = Custodian04;

------- Database User
-- Create a database user
Create user jack from login admin;
Create user jason for login jackson;

Create user jack from login admin with default_schema = temp_schema;

-- Start the guest user (not recommended)
-- Special users dbo and guest; dbo users corresponding to sa. Other users without ing are guest users.
Grant connect to guest;

-- Modify a user
Alter user jack with name = jason;
Alter user jason with default_schema = jason_schema;

-- Delete a user
Drop user jason;

-------- Database role
-- Grant the buyers role to the jack user
Create role buyers authorIzation jack;

-- Modify a role
Alter role buyers with name = new_buyers;

-- Delete a role
Drop role new_buyers;

-------- Architecture Management
-- Create
Create schema temp_schema;

-- Specify a user
Create schema jason_scheam authorization jason;

-- Authorization Query
Grant select to jason;

-- Delete
Drop schema jason_scheam;

-------- Permission
-- Authorize table Creation
Grant create table to jason;
-- Authorize jason to query the student table
Grant select on student to jason;

-- Revoke permissions
Revoke create table to jason;
Revoke select on student to jason;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.