Use a T-SQL script to create a role in SQL Server and grant the role the appropriate Permissions

Source: Internet
Author: User
-- Add a role, grant permissions to the role, and then add the user to the role.

-- Create role r_test
EXEC sp_addrole 'r _ Test'

-- Grant r_test all permissions on the jobs table
Grant all on jobs TO r_test
-- Grant the role r_test the SELECT permission on the titles table.
Grant select on titles TO r_test

-- Add login l_test and set the password to pwd. The default value is Database Pubs
EXEC sp_addlogin 'l _ test', 'pwd', 'pubs'

-- Add to database pubs for login l_test Security Account u_test
EXEC sp_grantdbaccess 'l _ test', 'U _ Test'

-- Add u_test as a member of role r_test
EXEC sp_addrolemember 'r _ test', 'U _ Test'
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.