views:

5671

answers:

4

What is the exact SQL to assign db_datareader and db_datawriter roles to a user in SQL Server?

Say the user name is MYUSER and the DB in question is MYDB.

Thanks!

+10  A: 
use mydb
go

exec sp_addrolemember db_datareader, MYUSER 
go
exec sp_addrolemember db_datawriter , MYUSER 
go
cmsjr
Of course, it's better to assign rights to groups/roles instead of individual users, but this does answer the question.
casperOne
Actually, db_datareader and db_datawriter are predefined database roles, so this is a case of assigning users to roles.
cmsjr
A: 

I think casperOne means Active Directory type groups/roles which users can be added to easily. Of course, if your model uses SQL Security, this is a moot point.

In any case, this was exactly what I was looking for. Thanks!

Tim
A: 

Using this permission only Tables can be viewed and edit. what are the permission to modify Stored procedures, functions, etc Please ...

Pankaj
Ask your own question ;-)
consultutah
A: 

That's ok if its on the wrong question here is the answer:

GRANT EXECUTE to MYUSER ; /* Grant to all store procs */
GO
GRANT EXECUTE ON USP_LOADSOMEDATA TO MYUSER; /* Grant to as specific store procs */
vsmike