T-SQL Tutorial

T-SQL Grant


This article describes how to grant privileges, roles or permissions on SQL Server database objects.
The T-SQL statement GRANT is used to grant permissions in a database.
Rights such as select, insert, update, delete on a table can be granted to a specific user using the grant statement.



Grant syntax

GRANT SELECT ON table_name TO user_name;
GRANT SELECT ON view_name TO user_name;
GRANT EXECUTE ON OBJECT::procedure_name TO user_name;
GRANT SELECT ON SCHEMA::schema_name TO user_name;


Grant example

GO
CREATE USER test_user FOR LOGIN [DomainName\WindowsUser];
GO
GRANT SELECT courses_view TO test_user;
GRANT SELECT, INSERT, UPDATE, DELETE ON books TO test_user;
GRANT SELECT ON SCHEMA::test_schema TO test_user;
GRANT EXECUTE ON OBJECT::CourseSales TO test_user;
DROP USER test_user;
GO