(Original) Use timestamp to control concurrency [Example]-create a background database script

Source: Internet
Author: User
Complete example http://files.cnblogs.com/Hedonister/TimeStamp.rar

Run the background script file used by the instance directly:

1 Create Database t_timestamp
2 Go
3 If Exists (select * From DBO. sysobjects where ID = Object_id (n ' [DBO]. [getdata] ' ) And objectproperty (ID, n ' Isprocedure ' ) =   1 )
4 Drop procedure [DBO]. [getdata]
5 Go
6 If Exists (select * From DBO. sysobjects where ID = Object_id (n ' [DBO]. [deletedata] ' ) And objectproperty (ID, n ' Isprocedure ' ) =   1 )
7 Drop procedure [DBO]. [deletedata]
8 Go
9 If Exists (select * From DBO. sysobjects where ID = Object_id (n ' [DBO]. [insertdata] ' ) And objectproperty (ID, n ' Isprocedure ' ) =   1 )
10 Drop procedure [DBO]. [insertdata]
11 Go
12 If Exists (select * From DBO. sysobjects where ID = Object_id (n ' [DBO]. [updatedata] ' ) And objectproperty (ID, n ' Isprocedure ' ) =   1 )
13 Drop procedure [DBO]. [updatedata]
14 Go
15 If Exists (select * From DBO. sysobjects where ID = Object_id (n ' [DBO]. [t_timestamp] ' ) And objectproperty (ID, n ' Isusertable ' ) =   1 )
16 Drop table [DBO]. [t_timestamp]
17 Go
18 If Not exists (select * From DBO. sysobjects where ID = Object_id (n ' [DBO]. [t_timestamp] ' ) And objectproperty (ID, n ' Isusertable ' ) =   1 )
19 Begin
20 Create 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]
25 End
26 Go
27 Alter table [DBO]. [t_timestamp] With nocheck add
28 Constraint [pk_t_timestamp] primary key clustered
29 (
30 [Kid]
31 ) On [primary]
32 Go
33 Set quoted_identifier off
34 Go
35 Set ansi_nulls off
36 Go
37 Create procedure getdata
38 @ Kid Int
39 As
40 Select * From t_timestamp
41 Go
42 Set quoted_identifier off
43 Go
44 Set ansi_nulls on
45 Go
46 Set quoted_identifier off
47 Go
48 Set ansi_nulls off
49 Go
50 Create procedure deletedata
51 @ Kid Int
52 As
53 Delete from t_timestamp where kid = @ Kid
54 Go
55 Set quoted_identifier off
56 Go
57 Set ansi_nulls on
58 Go
59 Set quoted_identifier off
60 Go
61 Set ansi_nulls off
62 Go
63 Create procedure insertdata
64 @ Kid Int ,
65 @ Name Char ( 10 )
66 As
67 Declare @ count Int
68 Select @ count = Count ( * ) From t_timestamp where kid = @ Kid
69 If @ count >   0  
70 Begin
71 Set @ kid = @ Kid +   1
72 End
73 Insert into t_timestamp
74 Values (@ kid, @ name, Null )
75 Go
76 Set quoted_identifier off
77 Go
78 Set ansi_nulls on
79 Go
80 Set quoted_identifier off
81 Go
82 Set ansi_nulls off
83 Go
84 Create procedure updatedata
85 @ Kid Int ,
86 @ Name Char ( 10 ),
87 @ Timestamp Timestamp
88 As
89 Update t_timestamp
90 Set Name = @ Name
91 Where kid = @ Kid
92 And Timestamp = @ Timestamp
93 Go
94 Set quoted_identifier off
95 Go
96 Set ansi_nulls on
97 Go
98
99

(Original) Use timestamp to control concurrency [Example]-Brief Description
(Original) Use timestamp to control concurrency [Example]-. CS script
(Original) Use timestamp to control concurrency [Example]-webpage HTML Script

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.