1ALTER PROCEDURE [dbo].aspnet_Applications_CreateApplication
2 @ApplicationName NVARCHAR(256),
3 @ApplicationId UNIQUEIDENTIFIER OUTPUT
4AS
5BEGIN
6 SELECT @ApplicationId = ApplicationId FROM dbo.aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName
7
8 IF(@ApplicationId IS NULL) /*如果应用程序ID为空则进行如下操作*/
9 BEGIN
10 DECLARE @TranStarted BIT
11 SET @TranStarted = 0
12
13 IF( @@TRANCOUNT = 0 ) /*如果当前连接的活动事务数为零,则开始事务*/
14 BEGIN
15 BEGIN TRANSACTION
16 SET @TranStarted = 1 /*开始事务,设置事务参数为一*/
17 END
18 ELSE
19 SET @TranStarted = 0 /*如果当前连接的活动事务数不为零, 设置事务参数为0*/
20
21 SELECT @ApplicationId = ApplicationId
22 FROM dbo.aspnet_Applications WITH (UPDLOCK, HOLDLOCK)
23 WHERE LOWER(@ApplicationName) = LoweredApplicationName
24
25 IF(@ApplicationId IS NULL) /*继续判断(不过此处多了WITH)*/
26 BEGIN
27 SELECT @ApplicationId = NEWID()
28 INSERT dbo.aspnet_Applications (ApplicationId, ApplicationName, LoweredApplicationName)
29 VALUES (@ApplicationId, @ApplicationName, LOWER(@ApplicationName))
30 /*如果为空就为表插入新数据,NEWID()创建 uniqueidentifier 类型的唯一值,返回类型为*/
31 END
32
33
34 IF( @TranStarted = 1 )
35 BEGIN
36 IF(@@ERROR = 0) /*如果返回错误为0*/
37 BEGIN
38 SET @TranStarted = 0 /*重新设置事务参数为0*/
39 COMMIT TRANSACTION /*结束事务*/
40 END
41 ELSE
42 BEGIN
43 SET @TranStarted = 0
44 ROLLBACK TRANSACTION /*回滚事务*/
45 END
46 END
47 END
48END
49
50GO
第一个,哈。
2 @ApplicationName NVARCHAR(256),
3 @ApplicationId UNIQUEIDENTIFIER OUTPUT
4AS
5BEGIN
6 SELECT @ApplicationId = ApplicationId FROM dbo.aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName
7
8 IF(@ApplicationId IS NULL) /*如果应用程序ID为空则进行如下操作*/
9 BEGIN
10 DECLARE @TranStarted BIT
11 SET @TranStarted = 0
12
13 IF( @@TRANCOUNT = 0 ) /*如果当前连接的活动事务数为零,则开始事务*/
14 BEGIN
15 BEGIN TRANSACTION
16 SET @TranStarted = 1 /*开始事务,设置事务参数为一*/
17 END
18 ELSE
19 SET @TranStarted = 0 /*如果当前连接的活动事务数不为零, 设置事务参数为0*/
20
21 SELECT @ApplicationId = ApplicationId
22 FROM dbo.aspnet_Applications WITH (UPDLOCK, HOLDLOCK)
23 WHERE LOWER(@ApplicationName) = LoweredApplicationName
24
25 IF(@ApplicationId IS NULL) /*继续判断(不过此处多了WITH)*/
26 BEGIN
27 SELECT @ApplicationId = NEWID()
28 INSERT dbo.aspnet_Applications (ApplicationId, ApplicationName, LoweredApplicationName)
29 VALUES (@ApplicationId, @ApplicationName, LOWER(@ApplicationName))
30 /*如果为空就为表插入新数据,NEWID()创建 uniqueidentifier 类型的唯一值,返回类型为*/
31 END
32
33
34 IF( @TranStarted = 1 )
35 BEGIN
36 IF(@@ERROR = 0) /*如果返回错误为0*/
37 BEGIN
38 SET @TranStarted = 0 /*重新设置事务参数为0*/
39 COMMIT TRANSACTION /*结束事务*/
40 END
41 ELSE
42 BEGIN
43 SET @TranStarted = 0
44 ROLLBACK TRANSACTION /*回滚事务*/
45 END
46 END
47 END
48END
49
50GO