Add db_datareader and db_datawriter roles to a user for a database.

USE [dbname]
GO

/****** Object:  User [domain\user]    Script Date: 05/26/2011 05:37:39 ******/
IF  EXISTS (SELECT * FROM sys.database_principals WHERE name = N’domain\user’)
DROP USER [domain\user]
GO

USE [dbname]
GO

/****** Object:  User [domain\user]    Script Date: 05/26/2011 05:37:39 ******/
GO

CREATE USER [domain\user] FOR LOGIN [domain\user] WITH DEFAULT_SCHEMA=[dbo]
GO

EXEC sp_addrolemember N’db_datareader’, N’domain\user’
EXEC sp_addrolemember N’db_datawriter’, N’domain\user’

GO

One thought on “Add db_datareader and db_datawriter roles to a user for a database.”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: