DEFINITIONS

Definitions More Info.
Definition ID232
TitleSQL
CategorySCRIPT
DefinitionBir database tum login user assign edip yetkilendirme kodu
Definition Description--USERLAR CHECKDB DATABASE ASSIGN EDILIR
--LOGINLER BELIRLENIR
DECLARE @login VARCHAR(100) DECLARE @CommandToExecute VARCHAR(8000)
DECLARE login_cur CURSOR fast_forward FOR SELECT l.name
FROM master..syslogins l
INNER JOIN sys.databases d ON l.dbname = d.name
WHERE l.name NOT LIKE '%#%'
AND l.name NOT LIKE '%\%'
AND l.name NOT IN('sa',
'admin')
AND d.is_read_only = 0
ORDER BY
l.name OPEN login_cur;

FETCH NEXT
FROM
login_cur INTO
@login WHILE @@FETCH_STATUS = 0
BEGIN
SET
@CommandToExecute =+ CHAR(13)+ CHAR(10)
+ 'USE CHECKDB' + CHAR(13)+ CHAR(10)
+ 'IF EXISTS(SELECT NAME FROM SYSUSERS )' + CHAR(13)+ CHAR(10)
+ 'BEGIN' + CHAR(13)+ CHAR(10)
+ ' DROP USER [' + @login + ']' + CHAR(13)+ CHAR(10)
+ 'END' + CHAR(13)+ CHAR(10)
+ 'CREATE USER [' + @login + '] FOR LOGIN [' + @login + ']' + CHAR(13)+ CHAR(10) + CHAR(13)+ CHAR(10)
+ 'USE CHECKDB' + CHAR(13)+ CHAR(10)
+ 'GRANT INSERT TO [' + @login + ']' + CHAR(13)+ CHAR(10)
print (@CommandToExecute)
--EXEC (@CommandToExecute)
FETCH NEXT FROM
login_cur INTO
@login
END CLOSE login_cur;

DEALLOCATE login_cur;
GO
RecordBycunay
Record Date16-08-2012 15:21:50
Düzenle
Kopyala
Sil