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