Sunday, October 31, 2010

Create a user/assign role for a Single Database

We DBA have a great responsibility to avoid access to unauthorized access to users. So we can give access to users for Required Databases only. Following are the method to create/assign used for a single DB.

USE [DatabaseName]
GO

CREATE USER [LoginName] FOR LOGIN [LoginName]
GO

USE [DatabaseName]
GO

ALTER USER [LoginName] WITH DEFAULT_SCHEMA=[dbo]
GO

USE [DatabaseName]
GO

EXEC sp_addrolemember N'db_owner', N'LoginName'
GO

No comments:

Post a Comment