Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone,
I'm creating a User and Login for one of my databases below:
SQL
USE HWProjectView
GO

IF
  NOT EXISTS(SELECT * FROM sys.sql_logins WHERE name=N'HWProjectViewUser')
BEGIN
  CREATE LOGIN [HWProjectViewUser] WITH PASSWORD='My_P4SsW0Rd-H3R3'
END

IF
  NOT EXISTS(SELECT * FROM sys.database_principals WHERE name=N'HWProjectViewUser')
BEGIN
  CREATE USER [HWProjectViewUser] FOR LOGIN [HWProjectViewUser]
  EXEC sp_addrolemember N'TOMDEV\EXPRESS2012', N'HWProjectViewUser'
END

GO

But I need this user to have permissions so that they can SELECT, INSERT, UPDATE & DELETE from the tables within my database.

HOW??!?!?!

Please help.
Posted
Comments
Member 9581488 20-Dec-12 9:43am    
if you want to set permissions you can go to Database properties and in the new window select permission. Again select your UserName and grant all permission by checking different option!
thomasriley 20-Dec-12 9:48am    
I've seen how to do it in the interface, but I'd like to script it so I can:
1. Understand it better
2. Add multiple users quickly
If you have any ideas on this it'd be greatly appreciated
thomasriley 20-Dec-12 9:48am    
Its something to do with the GRANT keyword I'm sure!
Member 9581488 20-Dec-12 11:59am    
Hope this helps you.
http://stackoverflow.com/questions/6688880/how-do-i-grant-read-access-for-a-user-to-a-database-in-sql-server

1 solution

You can see the script the interface uses by:
1. Add permissions in the interface (but do not click the OK button)
2. Click the script button at the top of the interface
3. Choose "Script Action to New Query Window"

A query window will open with the script you need to add the permissions.
 
Share this answer
 
Comments
thomasriley 8-Jan-13 5:49am    
Thankyou Dave

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900