提问人:Sergio 提问时间:11/13/2023 最后编辑:jarlhSergio 更新时间:11/13/2023 访问量:61
SQL Server 事务处理为所有数据库的所有表提供权限/权限
SQL Server transact give permisions/privileges to all tables for all databases
问:
我正在尝试将所有数据库的权限授予用户,但我没有找到。
我只知道如何为一个数据库做到这一点:
use bd_flights
grant select on schema::dbo to USER1 WITH GRANT OPTION
有没有办法为您拥有的所有数据库执行此操作?
谢谢你,
我尝试过,但这仅适用于我所在的活动数据库。grant select on schema::dbo to USER1 WITH GRANT OPTION
答:
-1赞
AztecCodes
11/13/2023
#1
示例实现:
DECLARE @DbName nvarchar(100)
DECLARE @Command nvarchar(max)
DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb')
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @DbName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @Command = 'USE [' + @DbName + ']; GRANT SELECT ON SCHEMA::dbo TO USER1 WITH GRANT OPTION;'
EXEC sp_executesql @Command
FETCH NEXT FROM db_cursor INTO @DbName
END
CLOSE db_cursor
DEALLOCATE db_cursor
评论
grant select on schema::dbo to USER1
connect any database
view any database