Skip to main content

Lock/Unlock objects

-----------------------------------VARIABLE DECLARATION----------------------------------
DECLARE @DatabaseName SYSNAME,
@Statement NVARCHAR(MAX),
@LockedBy NVARCHAR(30),
@Locked TINYINT
-----------------------------------------PRE STEP----------------------------------------

SET @DatabaseName = N''
SET @LockedBy = N''
SET @Locked = 0 --Set to 1 for lock

-------------------------------DO NOT EDIT UNDER THIS LINE-------------------------------
SET @Statement = N'UPDATE [' + @DatabaseName + '].[dbo].[Object] SET [Locked] = @locked, [Locked By] = CONVERT(NVARCHAR(30), @lockedby) WHERE [Type] IN (1, 3, 5, 6, 7, 8, 9)';

EXEC sp_executesql @Statement,
@parameters = N'@locked tinyint, @lockedby Nvarchar(30)',
@locked = @Locked,
@lockedby = @LockedBy