April 25, 2012

sp_getapplock (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_getapplock(nvarchar @Resource
, varchar @LockMode
, varchar @LockOwner
, int @LockTimeout
, nvarchar @DbPrincipal)

MetaData:

 create procedure sys.sp_getapplock -- - 1999/04/14 00:00  
@Resource nvarchar (255) = NULL, -- Resource to lock
@LockMode varchar (32), -- Lock mode
@LockOwner varchar (32) = 'Transaction', -- Lock Owner - [D = Transaction]
@LockTimeout int = NULL, -- Lock timeout [D = Session setting]
@DbPrincipal sysname = N'public' -- DB principal to use for name space and permissions
as

declare @mode integer
declare @owner integer
declare @result integer
declare @dbid integer

select @mode =
CASE @LockMode
When ('Shared') Then 3
When ('Update') Then 4
When ('Exclusive') Then 5
When ('IntentExclusive') Then 8
When ('IntentShared') Then 6
Else -1
END

if @mode = -1
begin
raiserror(15625, -1, -1, @LockMode, N'@LockMode')
return (-999)
end

select @owner =
CASE @LockOwner
When ('Transaction') Then 1
When ('Session') Then 3
Else -1
END

if @owner = -1
begin
raiserror(15625, -1, -1, @LockOwner, N'@LockOwner')
return (-999)
end

if @LockTimeout is null
begin
set @LockTimeout = @@LOCK_TIMEOUT
end

select @dbid = db_id ()

if @owner = 1 and @@trancount = 0
begin
raiserror(15626, -1, -1)
return (-999)
end

exec @result = sys.xp_userlock 0, @dbid, @DbPrincipal, @Resource, @mode, @owner, @LockTimeout

return @result

No comments:

Post a Comment

Total Pageviews