-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_procedure.sql
91 lines (60 loc) · 1.62 KB
/
test_procedure.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
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
91
USE `second_hand_trading_system`;
# 随机生成任意长度的字符串
DELIMITER //
CREATE FUNCTION rand_string(len integer)
returns text no sql
BEGIN
declare counter int default 1;
declare str text default '';
if len < 1 then
return null;
end if;
while counter <= len do
set str = concat(str, char(floor(rand() * 94) + 33));
set counter = counter + 1;
end while;
return str;
END
//
DELIMITER ;
# 将记录插入product表
DELIMITER //
CREATE PROCEDURE InsertProduct()
BEGIN
DECLARE i INT DEFAULT 1;
WHILE i <= 10000 DO
INSERT INTO product (name, description, price, category, upload_date, status, user_id) VALUES
(rand_string(floor(3 + rand() * 3)), rand_string(floor(3 + rand() * 3)), ROUND(RAND() * (100 - 1) + 1), rand_string(floor(3 + rand() * 3)), CURRENT_TIMESTAMP(), 'available', 3);
SET i = i + 1;
END WHILE;
END //
DELIMITER ;
# 将记录插入product_images表
DELIMITER //
CREATE PROCEDURE InsertProductImages()
BEGIN
DECLARE i INT DEFAULT 1;
DECLARE j INT DEFAULT 9;
WHILE i <= 10920 AND j <= 10928 DO
INSERT INTO product_images (productid, image_path, created_at) VALUES
(j, "../image/uploaded_image_7.jpg", CURRENT_TIMESTAMP());
SET i = i + 1;
SET j = j + 1;
END WHILE;
END //
DELIMITER ;
# 将记录插入order表
DELIMITER //
CREATE PROCEDURE InsertOrder()
BEGIN
DECLARE i INT DEFAULT 1;
WHILE i <= 10000 DO
INSERT INTO orders (buyer_id, seller_id, product_id, order_date, status) VALUES
(RAND() * 4 + 3, RAND() * 4 + 3, RAND() * (10928 - 7) + 7, CURRENT_TIMESTAMP(), 'completed');
SET i = i + 1;
END WHILE;
END //
DELIMITER ;
CALL InsertProduct();
CALL InsertProductImages();
CALL InsertOrder();