How to Grant Read / Write / Owner / Sysadmin Permission to All Tables and Views
USE [master]
GO
-- create the login
CREATE LOGIN [myuser] WITH PASSWORD = '1234'
-- create the user in the target database
--
change [PointInTIME] database with your desired database
USE [PointInTIME]
GO
CREATE USER
[myuser] FOR
LOGIN [read_only_user]
-- grant read-only access to the user
USE [PointInTIME]
GO
EXEC sp_addrolemember 'db_datareader', 'myuser'
-- grant write access to the user
USE [PointInTIME]
GO
EXEC sp_addrolemember 'db_datawriter', 'myuser'
-- grant owner access to the user
USE [PointInTIME]
GO
EXEC sp_addrolemember 'db_owner', 'myuser'
--grant Sysadmin access to the user
ALTER SERVER ROLE [sysadmin] ADD MEMBER [myuser];
0 Comments