Aspnetdb-stored procedure Research (aspnet_applications_createapplication)

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.