July 29, 2019 at 11:54 am
Need syntax for SQL 2017 to CREATE a brand new LOGIN (which is an existing Windows A/D group) and tie it as db_datareader for a specific DB called 'MyDatabase'.
July 29, 2019 at 12:23 pm
https://docs.microsoft.com/en-us/sql/t-sql/statements/create-login-transact-sql
https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-role-transact-sql
use master
create login [AD\user1] from windows
use [MyDatabase]
create user [AD\user1] for login [AD\user1]
alter role db_datareader add member [AD\user1]
July 29, 2019 at 12:37 pm
Andrey, thanks. This is very helpful. I was hoping there was a 1 line, auto-magical script which could perform much of this but I understand it is a multi-step process.. thx again!!
July 29, 2019 at 12:58 pm
Andrey, thanks. This is very helpful. I was hoping there was a 1 line, auto-magical script which could perform much of this but I understand it is a multi-step process.. thx again!!
you can speed up the process creating final script using sql like :
select 'use master; create login ['+name+'] from windows; use [MyDatabase]; create user ['+name+'] for login ['+name+']; alter role db_datareader add member '+quotename(name)+';' from tbl_names
tbl_names should contain all you 80 accounts in column name
run the script you get and job is done
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply