-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathorder.sql
55 lines (50 loc) · 1.46 KB
/
order.sql
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
drop database IF EXISTS ord;
create database ord;
use ord;
drop table IF EXISTS stock;
drop table IF EXISTS order1;
drop table IF EXISTS user_coupon;
drop table IF EXISTS pay;
create table stock(
id BIGINT(11) PRIMARY KEY AUTO_INCREMENT,
product_id int(11) not null,
stock int(11) not null,
create_time datetime DEFAULT current_timestamp,
update_time datetime DEFAULT current_timestamp,
unique key(product_id)
);
insert into stock(product_id, stock) VALUES (1, 100), (2, 200);
create table order1(
id BIGINT(11) PRIMARY KEY AUTO_INCREMENT,
order_id varchar(45),
user_id int(11) not null,
product_id int(11) not null,
amount int(11) not null,
status varchar(45) not null,
create_time datetime DEFAULT current_timestamp,
update_time datetime DEFAULT current_timestamp,
UNIQUE key(order_id),
key(product_id),
key(user_id)
);
create table user_coupon(
id BIGINT(11) PRIMARY KEY AUTO_INCREMENT,
user_id int(11) not null,
coupon_id int(11) not null,
used int(11) not null,
create_time datetime DEFAULT current_timestamp,
update_time datetime DEFAULT current_timestamp,
UNIQUE key(user_id, coupon_id),
key(coupon_id)
);
create table pay(
id BIGINT(11) PRIMARY KEY AUTO_INCREMENT,
user_id int(11) not null,
order_id varchar(45) not null,
amount int(11) not null,
status varchar(45) not null,
create_time datetime DEFAULT current_timestamp,
update_time datetime DEFAULT current_timestamp,
UNIQUE key(order_id),
key(user_id)
);