我正在使用 MSSQL Server Management Studio 2014。
我正在尝试创建一个可以查看数据库表、函数和用户的登录名。还为数据库生成脚本,但不运行脚本。登录名不能在数据库中删除、创建、删除或插入任何内容。
通过此尝试,用户无法查看数据库中的函数。
我应该怎么做才能创建这样的登录?
我正在使用 MSSQL Server Management Studio 2014。
我正在尝试创建一个可以查看数据库表、函数和用户的登录名。还为数据库生成脚本,但不运行脚本。登录名不能在数据库中删除、创建、删除或插入任何内容。
通过此尝试,用户无法查看数据库中的函数。
我应该怎么做才能创建这样的登录?
用这个
USE [DataPump]
GO
declare @login VARCHAR(30) = 'UserRevoke'
declare commands cursor for
SELECT 'Grant View Definition ON ' + schema_name(schema_id) + '.' + [name] + ' TO ' + '[' + REPLACE(REPLACE (@login, '[', ''), ']', '') + ']'
FROM sys.all_objects s
WHERE type IN ('P', 'V', 'FN', 'TR', 'IF', 'TF', 'U')
/*
P - Stored Procedure
V - View
FN - SQL scalar-function
TR - Trigger
IF - SQL inlined table-valued function
TF - SQL table-valued function
U - Table (user-defined)
*/
AND is_ms_shipped = 0
ORDER BY s.type, s.name
declare @cmd varchar(max)
open commands
fetch next from commands into @cmd
while @@FETCH_STATUS=0
begin
exec(@cmd)
fetch next from commands into @cmd
end
close commands
deallocate commands