adminbd

Записи по mssql,oracle,windows и linux

Have a Question?

If you have any question you can ask below or enter what you are looking for!

All posts tagged права

Как добавить права чтения или записи на базу, сразу многим пользователям.

declare @db nvarchar(max)
declare @sql nvarchar(max)
declare cursor_size_srv cursor for
SELECT  --@@SERVERNAME AS Server ,
        name AS DBName 
        --recovery_model_Desc AS RecoveryModel ,
        --Compatibility_level AS CompatiblityLevel ,
        --create_date ,
        --state_desc
FROM sys.server_principals
WHERE NAME LIKE 'HEAD_OFFICE\_Розничная сеть%'
ORDER BY Name; 
 
OPEN cursor_size_srv
FETCH NEXT FROM cursor_size_srv INTO @db
WHILE (@@FETCH_STATUS=0)
BEGIN
set @sql =

'USE [Demo_connect]
GO
CREATE USER ['+@db+'] FOR LOGIN ['+@db+']
GO
USE [Demo_connect]
GO
EXEC sp_addrolemember N''db_datareader'', N'''+@db+'''
GO'


print (@sql);
FETCH NEXT FROM cursor_size_srv INTO @db
END
CLOSE cursor_size_srv
DEALLOCATE cursor_size_srv