Use SQL scripts in SQL Server 2008 to create a logged in user and authorize

Source: Internet
Author: User

It is obviously unsafe to use the superuser sa everywhere, so there is a need to create a user and make it accessible to only one database. Of course, you can use the SQL Server's own graphical Interface wizard, but it's too hard to use! Sometimes the code is more straightforward, like this:

--using a database that has already been created UseMyDBGO--Create a login user and passwordEXECSp_addlogin N'Mydb_user','123456'--make Mydb_user a legitimate user of the current databaseEXECsp_grantdbaccess N'Mydb_user'--Grant Mydb_user all permissions to its own databaseEXECsp_addrolemember N'db_owner'N'Mydb_user'--Grant Mydb_user permission to operate on all user tablesGRANT SELECT,INSERT,UPDATE,DELETE  toMydb_user--Grant Mydb_user permission to create tables, views, stored proceduresGRANT CREATE TABLE,CREATE VIEW,CREATE PROC  toMydb_userGO

It's cool to use it!

End.

Use SQL scripts in SQL Server 2008 to create a logged in user and authorize

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.