Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grant Login Access using T-SQL 1

Status
Not open for further replies.

Ovatvvon

Programmer
Feb 1, 2001
1,514
US
Hi All,

I used the following code to add a login to the SQL Server:
Code:
CREATE LOGIN [{domain}\{user_id}] FROM WINDOWS WITH
	DEFAULT_DATABASE = {db_name},
	DEFAULT_LANGUAGE = us_english
which did grant the login access to the DBMS, however, I'm looking for a piece of code that will grant access for the specified ID to a specific database, with specific permissions (such as db_datareader / read-only).

I have not been able to find the right piece of code to do this.

Can anyone help?


-Ovatvvon :-Q
 
This is what your looking for now.

Code:
USE MyDB
GO
CREATE USER [user] FOR LOGIN [user] WITH DEFAULT_SCHEMA=[dbo]
GO
EXEC sp_addrolemember 'db_datareader', 'user'

- Paul
- If at first you don't succeed, find out if the loser gets anything.
 
Thanks Paul, I'll give that a try! :)

-Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top