Aspnet_applications_createapplication: used to create a role Application
If Exists ( Select * From DBO. sysobjects Where ID = Object_id (N ' [DBO]. [aspnet_applications_createapplication] ' ) And
Objectproperty (ID, n ' Isprocedure ' ) = 1 )
Drop Procedure [ DBO ] . [ Aspnet_applications_createapplication ]
Go
Set Quoted_identifier Off
Go
Set Ansi_nulls On
Go
-- This stored procedure mainly creates an application and returns Parameters
Create Procedure [ DBO ] . Aspnet_applications_createapplication
@ Applicationname Nvarchar ( 256 ),
@ Applicationid Uniqueidentifier Output
As
Begin
Select @ Applicationid = Applicationid From DBO. aspnet_applications Where Lower ( @ Applicationname ) =
Loweredapplicationname
-- If no application name ID is found, continue to check
If ( @ Applicationid Is Null )
Begin
Declare @ Transtarted Bit
Set @ Transtarted = 0
-- Start transaction
If ( @ Trancount = 0 )
Begin
Begin Transaction
Set @ Transtarted = 1
End
Else
Set @ Transtarted = 0
-- Updlock: Use the update lock when reading the table, instead of using the shared lock, and keep the lock until the statement or transaction ends. Updlock allows you to read data.
-- (Do not block other transactions), update data later, and ensure that the data has not been changed since the last data read.
-- Holdlock retains the shared lock until the transaction is completed, instead of releasing the lock immediately when the corresponding table, row, or data page no longer needs it.
-- Holdlock is equivalent to serializable.
Select @ Applicationid = Applicationid
From DBO. aspnet_applications With (Updlock, Holdlock )
Where Lower ( @ Applicationname ) = Loweredapplicationname
If ( @ Applicationid Is Null )
Begin
Select @ Applicationid = Newid ()
Insert DBO. aspnet_applications (applicationid, applicationname, loweredapplicationname)
Values ( @ Applicationid , @ Applicationname , Lower ( @ Applicationname ))
End
If ( @ Transtarted = 1 )
Begin
If ( @ Error = 0 )
Begin
Set @ Transtarted = 0
Commit Transaction
End
Else
Begin
Set @ Transtarted = 0
Rollback Transaction
End
End
End
End
Go
Set Quoted_identifier Off
Go
Set Ansi_nulls On
Go
tips: Lock
-- updlock: Used to update a table, instead of using a shared lock, and keeps the lock until the statement or transaction ends. Updlock allows you to read data
-- (other transactions are not blocked) and update data later. It also ensures that the data has not been changed since the last data read.
-- holdlock retains the shared lock to the completion of the transaction, instead of releasing the lock immediately when the corresponding table, row, or data page no longer needs it.
-- holdlock is equivalent to serializable.