(原创)使用TimeStamp控制并发问题[示例]-创建后台数据库脚本
完整例子https://files.cnblogs.com/Hedonister/TimeStamp.rar
实例所用后台脚本文件,直接运行即可:
(原创)使用TimeStamp控制并发问题[示例]-简要描述
(原创)使用TimeStamp控制并发问题[示例]-.cs脚本
(原创)使用TimeStamp控制并发问题[示例]-页面HTML脚本
实例所用后台脚本文件,直接运行即可:
1Create DataBase T_TimeStamp
2GO
3if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetData]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
4drop procedure [dbo].[GetData]
5GO
6if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[DeleteData]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
7drop procedure [dbo].[DeleteData]
8GO
9if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[InsertData]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
10drop procedure [dbo].[InsertData]
11GO
12if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UpdateData]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
13drop procedure [dbo].[UpdateData]
14GO
15if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[T_TimeStamp]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
16drop table [dbo].[T_TimeStamp]
17GO
18if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[T_TimeStamp]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
19 BEGIN
20CREATE TABLE [dbo].[T_TimeStamp] (
21 [KID] [int] NOT NULL ,
22 [Name] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ,
23 [TimeStamp] [timestamp] NOT NULL
24) ON [PRIMARY]
25END
26GO
27ALTER TABLE [dbo].[T_TimeStamp] WITH NOCHECK ADD
28 CONSTRAINT [PK_T_TimeStamp] PRIMARY KEY CLUSTERED
29 (
30 [KID]
31 ) ON [PRIMARY]
32GO
33SET QUOTED_IDENTIFIER OFF
34GO
35SET ANSI_NULLS OFF
36GO
37CREATE PROCEDURE GetData
38@KID int
39 AS
40SELECT * FROM T_TimeStamp
41GO
42SET QUOTED_IDENTIFIER OFF
43GO
44SET ANSI_NULLS ON
45GO
46SET QUOTED_IDENTIFIER OFF
47GO
48SET ANSI_NULLS OFF
49GO
50CREATE PROCEDURE DeleteData
51@KID int
52 AS
53Delete FROM T_TimeStamp WHERE KID = @KID
54GO
55SET QUOTED_IDENTIFIER OFF
56GO
57SET ANSI_NULLS ON
58GO
59SET QUOTED_IDENTIFIER OFF
60GO
61SET ANSI_NULLS OFF
62GO
63CREATE PROCEDURE InsertData
64 @Kid int,
65 @Name char(10)
66 AS
67DECLARE @Count int
68SELECT @Count = COUNT(*) FROM T_TimeStamp WHERE KID = @Kid
69IF @Count > 0
70BEGIN
71Set @Kid = @Kid + 1
72END
73INSERT INTO T_TimeStamp
74VALUES(@Kid,@Name,null)
75GO
76SET QUOTED_IDENTIFIER OFF
77GO
78SET ANSI_NULLS ON
79GO
80SET QUOTED_IDENTIFIER OFF
81GO
82SET ANSI_NULLS OFF
83GO
84CREATE PROCEDURE UpdateData
85 @KID int,
86 @Name char(10),
87 @TimeStamp TimeStamp
88AS
89Update T_TimeStamp
90SET Name = @Name
91WHERE KID = @KID
92AND TimeStamp = @TimeStamp
93GO
94SET QUOTED_IDENTIFIER OFF
95GO
96SET ANSI_NULLS ON
97GO
98
99
2GO
3if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetData]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
4drop procedure [dbo].[GetData]
5GO
6if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[DeleteData]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
7drop procedure [dbo].[DeleteData]
8GO
9if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[InsertData]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
10drop procedure [dbo].[InsertData]
11GO
12if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UpdateData]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
13drop procedure [dbo].[UpdateData]
14GO
15if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[T_TimeStamp]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
16drop table [dbo].[T_TimeStamp]
17GO
18if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[T_TimeStamp]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
19 BEGIN
20CREATE TABLE [dbo].[T_TimeStamp] (
21 [KID] [int] NOT NULL ,
22 [Name] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ,
23 [TimeStamp] [timestamp] NOT NULL
24) ON [PRIMARY]
25END
26GO
27ALTER TABLE [dbo].[T_TimeStamp] WITH NOCHECK ADD
28 CONSTRAINT [PK_T_TimeStamp] PRIMARY KEY CLUSTERED
29 (
30 [KID]
31 ) ON [PRIMARY]
32GO
33SET QUOTED_IDENTIFIER OFF
34GO
35SET ANSI_NULLS OFF
36GO
37CREATE PROCEDURE GetData
38@KID int
39 AS
40SELECT * FROM T_TimeStamp
41GO
42SET QUOTED_IDENTIFIER OFF
43GO
44SET ANSI_NULLS ON
45GO
46SET QUOTED_IDENTIFIER OFF
47GO
48SET ANSI_NULLS OFF
49GO
50CREATE PROCEDURE DeleteData
51@KID int
52 AS
53Delete FROM T_TimeStamp WHERE KID = @KID
54GO
55SET QUOTED_IDENTIFIER OFF
56GO
57SET ANSI_NULLS ON
58GO
59SET QUOTED_IDENTIFIER OFF
60GO
61SET ANSI_NULLS OFF
62GO
63CREATE PROCEDURE InsertData
64 @Kid int,
65 @Name char(10)
66 AS
67DECLARE @Count int
68SELECT @Count = COUNT(*) FROM T_TimeStamp WHERE KID = @Kid
69IF @Count > 0
70BEGIN
71Set @Kid = @Kid + 1
72END
73INSERT INTO T_TimeStamp
74VALUES(@Kid,@Name,null)
75GO
76SET QUOTED_IDENTIFIER OFF
77GO
78SET ANSI_NULLS ON
79GO
80SET QUOTED_IDENTIFIER OFF
81GO
82SET ANSI_NULLS OFF
83GO
84CREATE PROCEDURE UpdateData
85 @KID int,
86 @Name char(10),
87 @TimeStamp TimeStamp
88AS
89Update T_TimeStamp
90SET Name = @Name
91WHERE KID = @KID
92AND TimeStamp = @TimeStamp
93GO
94SET QUOTED_IDENTIFIER OFF
95GO
96SET ANSI_NULLS ON
97GO
98
99
(原创)使用TimeStamp控制并发问题[示例]-简要描述
(原创)使用TimeStamp控制并发问题[示例]-.cs脚本
(原创)使用TimeStamp控制并发问题[示例]-页面HTML脚本