use master
go
declare
@username nvarchar(100)
, @password varchar(30)
set @username = 'domain\login'
set @password = 'p@ss'
declare @createlogin nvarchar(1000)
if @username like '%\%'
begin
set @createlogin = 'CREATE LOGIN [' + @username + '] FROM WINDOWS WITH DEFAULT_DATABASE=[master]'
end
else
begin
set @createlogin = 'CREATE LOGIN [' + @username + '] WITH PASSWORD=N''' + @password + ''', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF'
end
select 'USE master
GO
-- crerate login
' + @createlogin+ '
GO
-- TRACE
GRANT ALTER TRACE TO [' + @username + ']
GO'
union all select 'USE msdb
GO
-- 에이전트
EXEC sp_addrolemember N''SQLAgentReaderRole'', N''' + @username + '''
GO
DENY EXECUTE ON sp_update_job TO [' + @username + ']
GO
DENY EXECUTE ON sp_update_schedule TO [' + @username + ']
GO
DENY EXECUTE ON sp_add_job TO [' + @username + ']
GO'
union all select 'USE ' + name + '
GO
-- 계정생성
CREATE USER ['+ @username + '] FOR LOGIN [' + @username + ']
GO
-- dbo 할당
ALTER USER [' + @username + '] WITH DEFAULT_SCHEMA=[dbo]
GO
-- 실행권한
GRANT EXECUTE TO [' + @username + ']
GO
-- 정의보기
GRANT VIEW DEFINITION ON SCHEMA::[dbo] TO [' + @username + ']
GO
-- 실행계획보기
GRANT SHOWPLAN TO [' + @username + ']
GO
-- 데이터읽기
EXEC sp_addrolemember N''db_datareader'', N''' + @username + '''
GO
-- 데이터쓰기
EXEC sp_addrolemember N''db_datawriter'', N''' + @username + '''
GO
-- dbowner
EXEC sp_addrolemember N''db_owner'', N''' + @username + '''
GO
-- ddladmin
EXEC sp_droprolemember N''db_ddladmin'', N''' + @username + '''
GO'
from sys.databases
where database_id > 4 and name not in ('distribution')
'SQL Server' 카테고리의 다른 글
프로시저에 참조된 테이블 검색 (0) | 2019.08.27 |
---|---|
DB 백업 & 복구 스크립트 (0) | 2019.06.27 |
DB 업그레이드 절차 (0) | 2013.07.04 |
tempdb 튜닝 (0) | 2013.07.04 |
DB 이전 후 계정 변경 (0) | 2013.04.30 |