0

Please consider this scenario: I have 2 Schemas: SCHEMA1, SCHEMA2

In each schema I have some tables.

I have two logins for each schemas.

I want to create a user that can access (CRUD operation) on all tables in SCHEMA1 but just can Insert in SCHEMA2.Table1.

How can I create this user?

Thanks

1 Answer 1

2

something like this?

USE master
GO

CREATE LOGIN MyLogin WITH PASSWORD = 'xyz';

USE mydb
GO

CREATE USER MyLogin for login MyLogin;

GRANT SELECT, INSERT, UPDATE, DELETE ON SCHEMA :: SCHEMA1 TO MyLogin;

GRANT INSERT ON [SCHEMA2].[Table1] TO MyLogin;
2
  • Thanks. 1 more question. Mylogin should have access to just SCHEMA1 objects. Is it necessary to deny access on SCHEMA2 objects before last line?
    – DooDoo
    Commented Jan 8 at 10:14
  • 2
    @DooDoo, MyLogin will only have permissions explicitly granted to the user plus roles the user belongs to, including public. An explicit DENY is only needed when you want to negate permissions inherited via role membership. A DENY is not needed with the script in this answer as long as you have not granted object permissions to the public role.
    – Dan Guzman
    Commented Jan 8 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.