-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSQL.sql
More file actions
91 lines (81 loc) · 1.88 KB
/
SQL.sql
File metadata and controls
91 lines (81 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
create table border
(
orderid bigint not null,
email varchar(30) not null,
gid bigint not null,
number int not null,
buytime datetime default CURRENT_TIMESTAMP not null,
constraint `PRIMARY`
primary key (orderid)
)
;
create index gid
on border (gid)
;
create table cart
(
orderid bigint not null,
email varchar(30) not null,
gid bigint not null,
number int not null,
constraint `PRIMARY`
primary key (orderid)
)
;
create index gid
on cart (gid)
;
create table good
(
gid bigint not null,
gname varchar(100) not null,
brand varchar(10) null,
price float(6,2) not null,
number int not null,
constraint `PRIMARY`
primary key (gid)
)
;
alter table border
add constraint border_ibfk_1
foreign key (gid) references web.good (gid)
;
alter table cart
add constraint cart_ibfk_1
foreign key (gid) references web.good (gid)
;
create table user
(
username varchar(20) null,
email varchar(30) not null,
password varchar(20) not null,
constraint `PRIMARY`
primary key (email)
)
;
create procedure buy (IN pid bigint, IN pe varchar(30), IN pgid bigint, IN num int)
CREATE PROCEDURE `buy`(`pid` BIGINT(20), `pe` VARCHAR(30), `pgid` BIGINT(20), `num` INT(11))
BEGIN
INSERT INTO border (orderid, email, gid, number)
VALUES (pid, pe, pgid, num);
DELETE FROM cart
WHERE orderid = pid;
UPDATE good
SET number = number - num
WHERE gid = pgid;
END;
create procedure cart_merge (IN pid bigint, IN pemail varchar(30), IN pgid bigint, IN num int)
CREATE PROCEDURE `cart_merge`(`pid` BIGINT(20), `pemail` VARCHAR(30), `pgid` BIGINT(20), `num` INT(11))
BEGIN
DECLARE temp INT;
SELECT number
INTO temp
FROM cart
WHERE gid = pgid && email = pemail;
IF temp IS NULL
THEN INSERT INTO cart VALUES (pid, pemail, pgid, num);
ELSE UPDATE cart
SET orderid = pid, number = num + temp
WHERE gid = pgid && email = pemail;
END IF;
END;