我想在Sql server 2012中锁定一个sql表。需要的是该表只能由管理员打开。
答案 0 :(得分:0)
如果Userprofileid是Admin,其roleName为Admin,则为是。 示例:
CREATE PROCEDURE Procedurename
(@UserProfileid BIGINT)
AS
SET nocount ON;
BEGIN
IF( (SELECT R.NAME
FROM trn_userprofile UP(nolock)
INNER JOIN aspnetusers U(nolock)
ON u.id = up.userid
INNER JOIN dbo.aspnetuserroles UR(nolock)
ON U.id = UR.userid
INNER JOIN dbo.aspnetroles R(nolock)
ON UR.roleid = R.id
WHERE UP.userprofileid = @UserProfileid
AND UP.isactive = 1
AND UP.isdeleted = 0) = 'Admin' )
BEGIN
SELECT *
FROM tablename
END;
END;