How to grant access to couple of tables in sql server database

The best way is to create role and grant the needed access to the needed tables using that role:

CREATE ROLE CoupleOfTablesAccessRole
GRANT SELECT ON [dbo].[Table1] TO CoupleOfTablesAccessRole;

GRANT SELECT,INSERT,UPDATE,DELETE ON [dbo].[Table2] TO CoupleOfTablesAccessRole;

USE [Database_Name]
GO
CREATE USER [ABC\xyz] FOR LOGIN [ABC\xyz] WITH DEFAULT_SCHEMA=[dbo]
GO
USE [Database_Name]
GO
EXEC sp_addrolemember ‘CoupleOfTablesAccessRole’, N’ABC\xyz’

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s