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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407
|
DROP TABLE IF EXISTS sell; DROP TABLE IF EXISTS hold_ ; DROP TABLE IF EXISTS order_ ;
DROP TABLE IF EXISTS consumer_get_coupon ; DROP TABLE IF EXISTS consumer_recieve_redpacket ; DROP TABLE IF EXISTS consumer_register_address ; DROP TABLE IF EXISTS friendship ; DROP TABLE IF EXISTS fan ; DROP TABLE IF EXISTS user_focus_user ; DROP TABLE IF EXISTS manage_subaccount ; DROP TABLE IF EXISTS shopping_cart ; DROP TABLE IF EXISTS collect ; DROP TABLE IF EXISTS watching_history ;
DROP TABLE IF EXISTS friend_and_friend ; DROP TABLE IF EXISTS seller_and_agent ; DROP TABLE IF EXISTS consumer_and_agent ; DROP TABLE IF EXISTS consumer_and_seller ; DROP TABLE IF EXISTS member_and_member ; DROP TABLE IF EXISTS group_members ; DROP TABLE IF EXISTS friend_request ; DROP TABLE IF EXISTS group_request ; DROP TABLE IF EXISTS reply ; DROP TABLE IF EXISTS consumer_give_evaluation ; DROP TABLE IF EXISTS consumer_ask_question ; DROP TABLE IF EXISTS consumer_reply_question ; DROP TABLE IF EXISTS consumer_focus_question ; DROP TABLE IF EXISTS consumer_have_archive ;
DROP TABLE IF EXISTS mark ; DROP TABLE IF EXISTS logistics ; DROP TABLE IF EXISTS food ; DROP TABLE IF EXISTS cloth ; DROP TABLE IF EXISTS ele_appliment ; DROP TABLE IF EXISTS ele_product ; DROP TABLE IF EXISTS makeup ; DROP TABLE IF EXISTS sport ; DROP TABLE IF EXISTS toy ; DROP TABLE IF EXISTS daily_necessarity ; DROP TABLE IF EXISTS discount ; DROP TABLE IF EXISTS store ; DROP TABLE IF EXISTS commodity ; DROP TABLE IF EXISTS historical_price ;
DROP TABLE IF EXISTS red_packet ; DROP TABLE IF EXISTS taobao_history ; DROP TABLE IF EXISTS address ; DROP TABLE IF EXISTS archive ; DROP TABLE IF EXISTS coupon ; DROP TABLE IF EXISTS users ; DROP TABLE IF EXISTS consumer ; DROP TABLE IF EXISTS seller ;
DROP TABLE IF EXISTS official_agent ; DROP TABLE IF EXISTS groups ; DROP TABLE IF EXISTS message ; DROP TABLE IF EXISTS conversation_message ; DROP TABLE IF EXISTS group_message ; DROP TABLE IF EXISTS request ; DROP TABLE IF EXISTS evaluation ; DROP TABLE IF EXISTS comments ; DROP TABLE IF EXISTS question ;
CREATE TABLE store( store_id VARCHAR(20) PRIMARY KEY, store_name VARCHAR(30) NOT NULL, tag VARCHAR(20), profile_photo VARCHAR(500), seller_id VARCHAR(20) NOT NULL, address VARCHAR(50), sales DOUBLE PRECISION, vis_num INT, ord_num INT, tr_rate INT, candidate_num INT, Lv INT, credit INT, ct_time TIMESTAMP, sub_account INT );
CREATE TABLE commodity( com_id VARCHAR(20) PRIMARY KEY, com_name VARCHAR(30) NOT NULL, category VARCHAR(20), price DOUBLE PRECISION, dis_price DOUBLE PRECISION, num INT, description VARCHAR(500), detail VARCHAR(2000), after_sale VARCHAR(100), up_time TIMESTAMP, com_image VARCHAR(500) );
CREATE TABLE discount( dis_id VARCHAR(20) PRIMARY KEY, st_time TIMESTAMP, end_time TIMESTAMP, allowance DOUBLE PRECISION );
CREATE TABLE historical_price( com_id VARCHAR(20) PRIMARY KEY, time TIMESTAMP, price DOUBLE PRECISION );
CREATE TABLE mark( store_id VARCHAR(20) PRIMARY KEY, quality DOUBLE PRECISION, service DOUBLE PRECISION, distribution DOUBLE PRECISION, com_score DOUBLE PRECISION );
CREATE TABLE logistics( com_id VARCHAR(20) PRIMARY KEY, deadline TIMESTAMP, price DOUBLE PRECISION, comp_name VARCHAR(100), send_addr VARCHAR(50), receive_addr VARCHAR(50) );
CREATE TABLE food( com_id VARCHAR(20) PRIMARY KEY, com_name VARCHAR(30) NOT NULL, category VARCHAR(20), price DOUBLE PRECISION, dis_price DOUBLE PRECISION, num INT, description VARCHAR(500), detail VARCHAR(2000), after_sale VARCHAR(100), up_time TIMESTAMP, com_image VARCHAR(500), shelf_life INT, weight VARCHAR(20), taste VARCHAR(20) ); CREATE table cloth( com_id VARCHAR(20) PRIMARY KEY, com_name VARCHAR(30) NOT NULL, category VARCHAR(20), price DOUBLE PRECISION, dis_price DOUBLE PRECISION, num INT, description VARCHAR(500), detail VARCHAR(2000), after_sale VARCHAR(100), up_time TIMESTAMP, com_image VARCHAR(500), type VARCHAR(20), size VARCHAR(20) );
CREATE TABLE ele_appliment( com_id VARCHAR(20) PRIMARY KEY, com_name VARCHAR(30) NOT NULL, category VARCHAR(20), price DOUBLE PRECISION, dis_price DOUBLE PRECISION, num INT, description VARCHAR(500), detail VARCHAR(2000), after_sale VARCHAR(100), up_time TIMESTAMP, com_image VARCHAR(500), paymentway VARCHAR(20), type VARCHAR(20), memory VARCHAR(20), safegaurd VARCHAR(20), net_type VARCHAR(20) ); CREATE TABLE ele_product( com_id VARCHAR(20) PRIMARY KEY, com_name VARCHAR(30) NOT NULL, category VARCHAR(20), price DOUBLE PRECISION, dis_price DOUBLE PRECISION, num INT, description VARCHAR(500), detail VARCHAR(2000), after_sale VARCHAR(100), up_time TIMESTAMP, com_image VARCHAR(500), paymentway VARCHAR(20), type VARCHAR(20), safegaurd VARCHAR(20) );
CREATE TABLE makeup( com_id VARCHAR(20) PRIMARY KEY, com_name VARCHAR(30) NOT NULL, category VARCHAR(20), price DOUBLE PRECISION, dis_price DOUBLE PRECISION, num INT, description VARCHAR(500), detail VARCHAR(2000), after_sale VARCHAR(100), up_time TIMESTAMP, com_image VARCHAR(500), type VARCHAR(20), weight VARCHAR(20) );
CREATE TABLE sport( com_id VARCHAR(20) PRIMARY KEY, com_name VARCHAR(30) NOT NULL, category VARCHAR(20), price DOUBLE PRECISION, dis_price DOUBLE PRECISION, num INT, description VARCHAR(500), detail VARCHAR(2000), after_sale VARCHAR(100), up_time TIMESTAMP, com_image VARCHAR(500), type VARCHAR(20), size VARCHAR(20) );
CREATE TABLE toy( com_id VARCHAR(20) PRIMARY KEY, com_name VARCHAR(30) NOT NULL, category VARCHAR(20), price DOUBLE PRECISION, dis_price DOUBLE PRECISION, num INT, description VARCHAR(500), detail VARCHAR(2000), after_sale VARCHAR(100), up_time TIMESTAMP, com_image VARCHAR(500), type VARCHAR(20), suit_age INT );
CREATE TABLE daily_necessarity( com_id VARCHAR(20) PRIMARY KEY, com_name VARCHAR(30) NOT NULL, category VARCHAR(20), price DOUBLE PRECISION, dis_price DOUBLE PRECISION, num INT, description VARCHAR(500), detail VARCHAR(2000), after_sale VARCHAR(100), up_time TIMESTAMP, com_image VARCHAR(500), type VARCHAR(20), weight VARCHAR(20) );
CREATE TABLE other( com_id VARCHAR(20) PRIMARY KEY, com_name VARCHAR(30) NOT NULL, category VARCHAR(20), price DOUBLE PRECISION, dis_price DOUBLE PRECISION, num INT, detail VARCHAR(2000), after_sale VARCHAR(100), up_time TIMESTAMP, com_image VARCHAR(500), description VARCHAR(200) );
CREATE TABLE sell( store_id VARCHAR(20), com_id VARCHAR(20), st_time TIMESTAMP, PRIMARY KEY (store_id,com_id), FOREIGN KEY (store_id) REFERENCES store (store_id), FOREIGN KEY (com_id) REFERENCES commodity (com_id) );
CREATE TABLE hold_( com_id VARCHAR(20), dis_id VARCHAR(20), PRIMARY KEY (com_id,dis_id), FOREIGN KEY (com_id) REFERENCES commodity (com_id), FOREIGN KEY (dis_id) REFERENCES discount (dis_id) );
CREATE TABLE order_( order_id VARCHAR(20) PRIMARY KEY, com_id VARCHAR(20), user_id VARCHAR(20), real_pay DOUBLE PRECISION, ct_time TIMESTAMP, pay_time TIMESTAMP, state VARCHAR(20), pickup_code VARCHAR(20), description VARCHAR(20), com_num INT );
CREATE TABLE users ( user_id VARCHAR(20) PRIMARY KEY, user_name VARCHAR(30) NULL DEFAULT NULL, password_ VARCHAR(20) NOT NULL CHECK (LENGTH(password_) >= 8), gender CHAR(1) NOT NULL CHECK (gender IN ('M','F')), telephone CHAR(11) NOT NULL, type_ VARCHAR(10) NOT NULL,CHECK (type_ IN ('consumer','seller')) );
CREATE TABLE consumer ( user_id VARCHAR(20) NOT NULL PRIMARY KEY, user_name VARCHAR(30) NULL DEFAULT NULL, password_ VARCHAR(20) NOT NULL CHECK (LENGTH(password_) >= 8), gender CHAR(1) NOT NULL CHECK (gender IN ('M','F')), telephone CHAR(11) NOT NULL, membership BOOLEAN NOT NULL, credit INT NOT NULL CHECK (credit >= 0), headshot VARCHAR(500) NULL DEFAULT NULL, fan_number INT NOT NULL CHECK (fan_number >= 0), focus_number INT NOT NULL CHECK (focus_number >= 0), likes INT NOT NULL CHECK (likes >= 0), change DOUBLE PRECISION NOT NULL CHECK (change >= 0), shopping_coin INT NOT NULL CHECK (shopping_coin >= 0), alipay VARCHAR(20) NULL DEFAULT NULL, type_ VARCHAR(10) NOT NULL,CHECK (type_ = 'consumer'), shopping_cart VARCHAR(3000) NULL DEFAULT NULL );
CREATE TABLE seller ( user_id VARCHAR(20) NOT NULL PRIMARY KEY, user_name VARCHAR(30) NULL DEFAULT NULL, password_ VARCHAR(20) NOT NULL CHECK (LENGTH(password_) >= 8), gender CHAR(1) NOT NULL CHECK (gender IN ('M','F')), telephone CHAR(11) NOT NULL, type_ VARCHAR(10) NOT NULL,CHECK (type_ = 'seller'), service_authority BOOLEAN NOT NULL, operator_authority BOOLEAN NOT NULL );
CREATE TABLE red_packet ( red_packet_id SERIAL NOT NULL PRIMARY KEY, name_ VARCHAR(30) NOT NULL, value_ DOUBLE PRECISION NOT NULL, condition_ VARCHAR(20) NOT NULL, end_date DATE NOT NULL );
CREATE TABLE coupon ( coupon_id SERIAL NOT NULL PRIMARY KEY, store_id VARCHAR(20) NOT NULL, value_ DOUBLE PRECISION NOT NULL, condition_ VARCHAR(20) NOT NULL, end_date DATE NOT NULL, FOREIGN KEY (store_id) REFERENCES store (store_id) );
CREATE TABLE taobao_history ( user_id VARCHAR(20) NOT NULL, register_date DATE NOT NULL, total_days INT NOT NULL CHECK (total_days >= 0), save_money DOUBLE PRECISION NOT NULL CHECK (save_money >= 0), month_spend_money DOUBLE PRECISION NOT NULL CHECK (month_spend_money >= 0), PRIMARY KEY (user_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id) );
CREATE TABLE address ( address_id SERIAL NOT NULL PRIMARY KEY, name_ VARCHAR(30) NOT NULL, telephone CHAR(11) NOT NULL, address VARCHAR(50) NOT NULL );
CREATE TABLE archive ( archive_id SERIAL NOT NULL PRIMARY KEY, height DOUBLE PRECISION NOT NULL CHECK (height > 0), weight DOUBLE PRECISION NOT NULL CHECK (weight > 0), shoe_size DOUBLE PRECISION NOT NULL CHECK (shoe_size >= 16 and shoe_size <= 45) );
CREATE TABLE friendship ( user1_id VARCHAR(20) NOT NULL, user2_id VARCHAR(20) NOT NULL, accept_date DATE NOT NULL, PRIMARY KEY (user1_id, user2_id), FOREIGN KEY (user1_id) REFERENCES consumer (user_id), FOREIGN KEY (user2_id) REFERENCES consumer (user_id) );
CREATE TABLE consumer_register_address ( user_id VARCHAR(20) NOT NULL, address_id SERIAL NOT NULL, common_address BOOLEAN NOT NULL, PRIMARY KEY (user_id, address_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id), FOREIGN KEY (address_id) REFERENCES address (address_id) );
CREATE TABLE fan ( user_id VARCHAR(20) NOT NULL, fan_id VARCHAR(20) NOT NULL, PRIMARY KEY (user_id, fan_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id), FOREIGN KEY (fan_id) REFERENCES consumer (user_id) );
CREATE TABLE user_focus_user ( user_id VARCHAR(20) NOT NULL, focus_id VARCHAR(20) NOT NULL, PRIMARY KEY (user_id, focus_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id), FOREIGN KEY (focus_id) REFERENCES consumer (user_id) );
CREATE TABLE consumer_recieve_redpacket ( user_id VARCHAR(20) NOT NULL, red_packet_id SERIAL NOT NULL, PRIMARY KEY (user_id, red_packet_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id), FOREIGN KEY (red_packet_id) REFERENCES red_packet (red_packet_id) );
CREATE TABLE consumer_get_coupon ( user_id VARCHAR(20) NOT NULL, coupon_id SERIAL NOT NULL, PRIMARY KEY (user_id, coupon_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id), FOREIGN KEY (coupon_id) REFERENCES coupon (coupon_id) );
CREATE TABLE manage_subaccount ( main_user_id VARCHAR(20) NOT NULL, sub_user_id VARCHAR(20) NOT NULL, PRIMARY KEY (main_user_id,sub_user_id), FOREIGN KEY (main_user_id) REFERENCES seller (user_id), FOREIGN KEY (sub_user_id) REFERENCES seller (user_id) );
CREATE TABLE consumer_have_archive ( user_id VARCHAR(20) NOT NULL, archive_id SERIAL NOT NULL, PRIMARY KEY (user_id,archive_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id), FOREIGN KEY (archive_id) REFERENCES archive (archive_id) );
CREATE TABLE collect ( user_id VARCHAR(20) NOT NULL, com_id VARCHAR(20) NOT NULL, collect_time DATE NOT NULL, PRIMARY KEY (user_id,com_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id), FOREIGN KEY (com_id) REFERENCES commodity (com_id) );
CREATE TABLE watching_history ( user_id VARCHAR(20) NOT NULL, com_id VARCHAR(20) NOT NULL, watch_time DATE NOT NULL, PRIMARY KEY (user_id,com_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id), FOREIGN KEY (com_id) REFERENCES commodity (com_id) );
CREATE TABLE official_agent( official_agent_id VARCHAR(20) PRIMARY KEY, telephone VARCHAR(20) NOT NULL, start_date TIMESTAMP NOT NULL, end_date TIMESTAMP NOT NULL );
CREATE TABLE groups( group_id VARCHAR(20) PRIMARY KEY, group_name VARCHAR(30) NOT NULL, created_date TIMESTAMP DEFAULT NULL, description VARCHAR(100) DEFAULT NULL, member_num INT CHECK(member_num >= 0) );
CREATE TABLE message( message_id VARCHAR(20) PRIMARY KEY, message_type VARCHAR(10) CHECK (message_type IN ('文本','语音','图片','视频')), message_content VARCHAR(500) NOT NULL, message_date TIMESTAMP NOT NULL );
CREATE TABLE conversation_message( message_id VARCHAR(20) PRIMARY KEY, message_type VARCHAR(10) CHECK (message_type IN ('文本','语音','图片','视频')), message_content VARCHAR(500) NOT NULL, message_date TIMESTAMP NOT NULL, isread BOOLEAN NOT NULL );
CREATE TABLE group_message( message_id VARCHAR(20) PRIMARY KEY, message_type VARCHAR(10) CHECK (message_type IN ('文本','语音','图片','视频')), message_content VARCHAR(500) NOT NULL, message_date TIMESTAMP NOT NULL );
CREATE TABLE request( request_id VARCHAR(20) PRIMARY KEY, request_status VARCHAR(10) CHECK (request_status IN ('未处理','已接受','已拒绝')), request_description VARCHAR(100) DEFAULT NULL, request_date TIMESTAMP NOT NULL );
CREATE TABLE evaluation( evaluation_id VARCHAR(20) PRIMARY KEY, evaluation_content_type VARCHAR(10) CHECK (evaluation_content_type IN ('文本','图片','视频')), evaluation_content VARCHAR(500) NOT NULL, isanonymous BOOLEAN NOT NULL, evaluation_type CHAR(1) CHECK (evaluation_type IN ('好','差')), evaluated_date TIMESTAMP NOT NULL, isfollow BOOLEAN NOT NULL, likes INT CHECK (likes >= 0), comment_num INT CHECK (comment_num >=0), comprehensive_evaluation INT check(comprehensive_evaluation IN (0,1,2,3,4,5)), description_match INT check(description_match IN (0,1,2,3,4,5)), logistics_service INT check(logistics_service IN (0,1,2,3,4,5)), service_attitude INT check(service_attitude IN (0,1,2,3,4,5)) );
CREATE TABLE comments( evaluation_id VARCHAR(20), user_id VARCHAR(30), comment_date TIMESTAMP, comment_type VARCHAR(10) CHECK (comment_type IN ('文本','图片','视频')), comment_content VARCHAR(500) NOT NULL, likes INT, PRIMARY KEY(evaluation_id, user_id, comment_date), FOREIGN KEY (evaluation_id) REFERENCES evaluation (evaluation_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id) );
CREATE TABLE question( question_id VARCHAR(20) PRIMARY KEY, question_content VARCHAR(500) NOT NULL, question_date TIMESTAMP DEFAULT NULL, reply_num INT CHECK(reply_num >= 0) );
CREATE TABLE friend_and_friend( sender_id VARCHAR(20), receiver_id VARCHAR(20), message_id VARCHAR(20), PRIMARY KEY(sender_id, receiver_id, message_id), FOREIGN KEY (sender_id) REFERENCES consumer (user_id), FOREIGN KEY (receiver_id) REFERENCES consumer (user_id), FOREIGN KEY (message_id) REFERENCES conversation_message (message_id) );
CREATE TABLE seller_and_agent( seller_id VARCHAR(20), official_agent_id VARCHAR(20), message_id VARCHAR(20), sender BOOLEAN NOT NULL, PRIMARY KEY(seller_id, official_agent_id, message_id), FOREIGN KEY (seller_id) REFERENCES seller (user_id), FOREIGN KEY (official_agent_id) REFERENCES official_agent (official_agent_id), FOREIGN KEY (message_id) REFERENCES conversation_message (message_id) );
CREATE TABLE consumer_and_agent( consumer_id VARCHAR(20), official_agent_id VARCHAR(20), message_id VARCHAR(20), sender BOOLEAN NOT NULL, PRIMARY KEY(consumer_id, official_agent_id, message_id), FOREIGN KEY (consumer_id) REFERENCES consumer (user_id), FOREIGN KEY (official_agent_id) REFERENCES official_agent (official_agent_id), FOREIGN KEY (message_id) REFERENCES conversation_message (message_id) );
CREATE TABLE consumer_and_seller( consumer_id VARCHAR(20), seller_id VARCHAR(20), message_id VARCHAR(20), sender BOOLEAN NOT NULL, PRIMARY KEY(consumer_id, seller_id, message_id), FOREIGN KEY (consumer_id) REFERENCES consumer (user_id), FOREIGN KEY (seller_id) REFERENCES seller (user_id), FOREIGN KEY (message_id) REFERENCES conversation_message (message_id) );
CREATE TABLE member_and_member( group_id VARCHAR(20), sender_id VARCHAR(20), message_id VARCHAR(20), PRIMARY KEY(group_id, sender_id, message_id), FOREIGN KEY (group_id) REFERENCES groups (group_id), FOREIGN KEY (sender_id) REFERENCES consumer (user_id), FOREIGN KEY (message_id) REFERENCES group_message (message_id) );
CREATE TABLE group_members( group_id VARCHAR(20), user_id VARCHAR(20), role VARCHAR(10) CHECK (role IN ('群主','管理员','普通成员')), PRIMARY KEY(group_id, user_id), FOREIGN KEY (group_id) REFERENCES groups (group_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id) );
CREATE TABLE friend_request( request_id VARCHAR(20), sender_id VARCHAR(20), receiver_id VARCHAR(20), PRIMARY KEY(request_id, sender_id, receiver_id), FOREIGN KEY (request_id) REFERENCES request (request_id), FOREIGN KEY (sender_id) REFERENCES consumer (user_id), FOREIGN KEY (receiver_id) REFERENCES consumer (user_id) );
CREATE TABLE group_request( request_id VARCHAR(20), group_id VARCHAR(20), user_id VARCHAR(20), PRIMARY KEY(request_id, group_id, user_id), FOREIGN KEY (request_id) REFERENCES request (request_id), FOREIGN KEY (group_id) REFERENCES groups (group_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id) );
CREATE TABLE reply( evaluation_id VARCHAR(20), user_id VARCHAR(20), reply_date DATE, reply_type VARCHAR(10) CHECK (reply_type IN ('文本','图片','视频')), reply_content VARCHAR(500) NOT NULL, likes INT CHECK(likes >= 0), PRIMARY KEY(evaluation_id, user_id, reply_date), FOREIGN KEY (evaluation_id) REFERENCES evaluation (evaluation_id), FOREIGN KEY (user_id) REFERENCES seller (user_id) );
CREATE TABLE consumer_give_evaluation( evaluation_id VARCHAR(20), user_id VARCHAR(20), com_id VARCHAR(20), PRIMARY KEY(evaluation_id, user_id, com_id), FOREIGN KEY (evaluation_id) REFERENCES evaluation (evaluation_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id), FOREIGN KEY (com_id) REFERENCES commodity (com_id) );
CREATE TABLE consumer_ask_question( question_id VARCHAR(20), user_id VARCHAR(20), com_id VARCHAR(20), PRIMARY KEY(question_id, user_id, com_id), FOREIGN KEY (question_id) REFERENCES question (question_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id), FOREIGN KEY (com_id) REFERENCES commodity (com_id) );
CREATE TABLE consumer_reply_question( question_id VARCHAR(20), user_id VARCHAR(20), reply_date TIMESTAMP, reply_content VARCHAR(500) NOT NULL, PRIMARY KEY(question_id, user_id, reply_date), FOREIGN KEY (question_id) REFERENCES question (question_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id) );
CREATE TABLE consumer_focus_question( question_id VARCHAR(20), user_id VARCHAR(20), focus_date TIMESTAMP DEFAULT NULL, PRIMARY KEY(question_id, user_id), FOREIGN KEY (question_id) REFERENCES question (question_id), FOREIGN KEY (user_id) REFERENCES consumer (user_id) );
CREATE VIEW com_food AS SELECT commodity.com_name, commodity.price, commodity.dis_price, commodity.description, commodity.detail, commodity.com_image, shelf_life, weight, taste FROM commodity join food on commodity.com_id = food.com_id where commodity.category = 'food'; DROP VIEW com_food; CREATE VIEW com_cloth AS SELECT commodity.com_name, commodity.price, commodity.dis_price, commodity.description, commodity.detail, commodity.com_image, type, size FROM commodity join cloth on commodity.com_id = cloth.com_id where commodity.category = 'cloth'; DROP VIEW com_cloth; CREATE VIEW com_ele_appliment AS SELECT commodity.com_name, commodity.price, commodity.dis_price, commodity.description, commodity.detail, commodity.com_image, paymentway, type, memory, safegaurd, net_type FROM commodity join ele_appliment on commodity.com_id = ele_appliment.com_id where commodity.category = 'ele_appliment'; DROP VIEW com_ele_appliment; CREATE VIEW com_ele_product AS SELECT commodity.com_name, commodity.price, commodity.dis_price, commodity.description, commodity.detail, commodity.com_image, paymentway, type, safegaurd FROM commodity join ele_product on commodity.com_id = ele_product.com_id where commodity.category = 'ele_product'; DROP VIEW com_ele_product; CREATE VIEW com_makeup AS SELECT commodity.com_name, commodity.price, commodity.dis_price, commodity.description, commodity.detail, commodity.com_image, type, weight FROM commodity join makeup on commodity.com_id = makeup.com_id where commodity.category = 'makeup'; DROP VIEW com_makeup; CREATE VIEW com_sport AS SELECT commodity.com_name, commodity.price, commodity.dis_price, commodity.description, commodity.detail, commodity.com_image, type, size FROM commodity join sport on commodity.com_id = sport.com_id where commodity.category = 'sport'; DROP VIEW com_sport; CREATE VIEW com_toy AS SELECT commodity.com_name, commodity.price, commodity.dis_price, commodity.description, commodity.detail, commodity.com_image, type, suit_age FROM commodity join toy on commodity.com_id = toy.com_id where commodity.category = 'toy'; DROP VIEW com_toy; CREATE VIEW com_daily_necessarity AS SELECT commodity.com_name, commodity.price, commodity.dis_price, commodity.description, commodity.detail, commodity.com_image, type, weight FROM commodity join daily_necessarity on commodity.com_id = daily_necessarity.com_id where commodity.category = 'daily_necessarity'; DROP VIEW com_daily_necessarity;
CREATE VIEW com_of_store AS SELECT com_name, category, num, price, dis_price, description, detail, com_image, after_sale, up_time FROM commodity join sell on commodity.com_id = sell.com_id where store_id = '012345678'; DROP VIEW com_of_store;
CREATE VIEW personal_browsing_history AS SELECT com_name, price, dis_price, description, detail, com_image, watch_time FROM commodity join watching_history on commodity.com_id = watching_history.com_id where user_id = '000111111'; DROP VIEW personal_browsing_history;
CREATE VIEW historical_commodity_price AS SELECT com_name, price, time FROM commodity join historical_price on commodity.com_id = historical_price.com_id where com_id = '54645645645'; DROP VIEW historical_commodity_price;
CREATE VIEW personal_collect_history AS SELECT com_name, price, dis_price, description, detail, com_image, collect_time FROM commodity join collect on commodity.com_id = collect.com_id where user_id = '000111111'; DROP VIEW personal_collect_history;
CREATE VIEW personal_order AS SELECT com_name, real_pay, pay_time, order_.description, detail, com_image, com_num, pickup_code FROM order_ join commodity on commodity.com_id = order_.com_id where user_id = '000111111'; DROP VIEW personal_order;
CREATE VIEW chat_history AS SELECT message_content, message_date FROM conversation_message join friend_and_friend on conversation_message.message_id = friend_and_friend.message_id where (sender_id = 'tb12345' AND receiver_id = 'tb12342') OR (sender_id = 'tb12342' AND receiver_id = 'tb12345') order by message_date; DROP VIEW chat_history;
SELECT * FROM com_food; SELECT * FROM com_cloth; SELECT * FROM com_ele_appliment; SELECT * FROM com_ele_product; SELECT * FROM com_makeup; SELECT * FROM com_sport; SELECT * FROM com_toy; SELECT * FROM com_daily_necessarity; SELECT * FROM chat_history;
CREATE OR REPLACE FUNCTION order_insert_trigger() RETURNS TRIGGER AS $$ BEGIN INSERT INTO logistics (com_id) VALUES (NEW.com_id); RETURN NEW; END; $$ LANGUAGE plpgsql;
CREATE TRIGGER insert_order_trigger AFTER INSERT ON order_ FOR EACH ROW EXECUTE FUNCTION order_insert_trigger();
DROP TRIGGER insert_order_trigger ON order_
CREATE OR REPLACE FUNCTION history_insert_trigger() RETURNS TRIGGER AS $$ BEGIN INSERT INTO historical_price (com_id,time,price) VALUES (NEW.com_id,NOW(),NEW.price); RETURN NEW; END; $$ LANGUAGE plpgsql;
CREATE TRIGGER insert_history_trigger AFTER UPDATE ON commodity FOR EACH ROW EXECUTE FUNCTION history_insert_trigger();
DROP TRIGGER insert_history_trigger ON commodity
CREATE OR REPLACE FUNCTION insert_comsubtable_function() RETURNS TRIGGER AS $$ BEGIN IF NEW.category = 'food' THEN INSERT INTO food(com_id,com_name,category,price,dis_price,num,description,detail,after_sale,up_time,com_image) VALUES (NEW.com_id,NEW.com_name,NEW.category,NEW.price,NEW.dis_price,NEW.num,NEW.description,NEW.detail,NEW.after_sale,NEW.up_time,NEW.com_image); ELSIF NEW.category = 'cloth' THEN INSERT INTO cloth(com_id,com_name,category,price,dis_price,num,description,detail,after_sale,up_time,com_image) VALUES (NEW.com_id,NEW.com_name,NEW.category,NEW.price,NEW.dis_price,NEW.num,NEW.description,NEW.detail,NEW.after_sale,NEW.up_time,NEW.com_image); ELSIF NEW.category = 'ele_appliment' THEN INSERT INTO ele_appliment(com_id,com_name,category,price,dis_price,num,description,detail,after_sale,up_time,com_image) VALUES (NEW.com_id,NEW.com_name,NEW.category,NEW.price,NEW.dis_price,NEW.num,NEW.description,NEW.detail,NEW.after_sale,NEW.up_time,NEW.com_image); ELSIF NEW.category = 'ele_product' THEN INSERT INTO ele_product(com_id,com_name,category,price,dis_price,num,description,detail,after_sale,up_time,com_image) VALUES (NEW.com_id,NEW.com_name,NEW.category,NEW.price,NEW.dis_price,NEW.num,NEW.description,NEW.detail,NEW.after_sale,NEW.up_time,NEW.com_image); ELSIF NEW.category = 'makeup' THEN INSERT INTO makeup(com_id,com_name,category,price,dis_price,num,description,detail,after_sale,up_time,com_image) VALUES (NEW.com_id,NEW.com_name,NEW.category,NEW.price,NEW.dis_price,NEW.num,NEW.description,NEW.detail,NEW.after_sale,NEW.up_time,NEW.com_image); ELSIF NEW.category = 'sport' THEN INSERT INTO sport(com_id,com_name,category,price,dis_price,num,description,detail,after_sale,up_time,com_image) VALUES (NEW.com_id,NEW.com_name,NEW.category,NEW.price,NEW.dis_price,NEW.num,NEW.description,NEW.detail,NEW.after_sale,NEW.up_time,NEW.com_image); ELSIF NEW.category = 'toy' THEN INSERT INTO toy(com_id,com_name,category,price,dis_price,num,description,detail,after_sale,up_time,com_image) VALUES (NEW.com_id,NEW.com_name,NEW.category,NEW.price,NEW.dis_price,NEW.num,NEW.description,NEW.detail,NEW.after_sale,NEW.up_time,NEW.com_image); ELSIF NEW.category = 'daily_necessarity' THEN INSERT INTO daily_necessarity(com_id,com_name,category,price,dis_price,num,description,detail,after_sale,up_time,com_image) VALUES (NEW.com_id,NEW.com_name,NEW.category,NEW.price,NEW.dis_price,NEW.num,NEW.description,NEW.detail,NEW.after_sale,NEW.up_time,NEW.com_image); ELSE INSERT INTO other(com_id,com_name,category,price,dis_price,num,description,detail,after_sale,up_time,com_image) VALUES (NEW.com_id,NEW.com_name,NEW.category,NEW.price,NEW.dis_price,NEW.num,NEW.description,NEW.detail,NEW.after_sale,NEW.up_time,NEW.com_image); END IF;
RETURN NEW; END; $$ LANGUAGE plpgsql;
CREATE TRIGGER insert_comsubtable_trigger AFTER INSERT ON commodity FOR EACH ROW EXECUTE FUNCTION insert_comsubtable_function(); DROP TRIGGER insert_comsubtable_trigger ON commodity
CREATE OR REPLACE FUNCTION update_comsubtable_function() RETURNS TRIGGER AS $$ BEGIN IF OLD.category = 'food' THEN UPDATE food SET com_name=NEW.com_name,category=NEW.category,price=NEW.price,dis_price=NEW.dis_price,num=NEW.num, description=NEW.description,detail=NEW.detail,after_sale=NEW.after_sale,up_time=NEW.up_time,com_image=NEW.com_image WHERE com_id=NEW.com_id; ELSIF OLD.category = 'cloth' THEN UPDATE cloth SET com_name=NEW.com_name,category=NEW.category,price=NEW.price,dis_price=NEW.dis_price,num=NEW.num, description=NEW.description,detail=NEW.detail,after_sale=NEW.after_sale,up_time=NEW.up_time,com_image=NEW.com_image WHERE com_id=NEW.com_id; ELSIF OLD.category = 'ele_appliment' THEN UPDATE ele_appliment SET com_name=NEW.com_name,category=NEW.category,price=NEW.price,dis_price=NEW.dis_price,num=NEW.num, description=NEW.description,detail=NEW.detail,after_sale=NEW.after_sale,up_time=NEW.up_time,com_image=NEW.com_image WHERE com_id=NEW.com_id; ELSIF OLD.category = 'ele_product' THEN UPDATE ele_product SET com_name=NEW.com_name,category=NEW.category,price=NEW.price,dis_price=NEW.dis_price,num=NEW.num, description=NEW.description,detail=NEW.detail,after_sale=NEW.after_sale,up_time=NEW.up_time,com_image=NEW.com_image WHERE com_id=NEW.com_id; ELSIF OLD.category = 'makeup' THEN UPDATE makeup SET com_name=NEW.com_name,category=NEW.category,price=NEW.price,dis_price=NEW.dis_price,num=NEW.num, description=NEW.description,detail=NEW.detail,after_sale=NEW.after_sale,up_time=NEW.up_time,com_image=NEW.com_image WHERE com_id=NEW.com_id; ELSIF OLD.category = 'sport' THEN UPDATE sport SET com_name=NEW.com_name,category=NEW.category,price=NEW.price,dis_price=NEW.dis_price,num=NEW.num, description=NEW.description,detail=NEW.detail,after_sale=NEW.after_sale,up_time=NEW.up_time,com_image=NEW.com_image WHERE com_id=NEW.com_id; ELSIF OLD.category = 'toy' THEN UPDATE toy SET com_name=NEW.com_name,category=NEW.category,price=NEW.price,dis_price=NEW.dis_price,num=NEW.num, description=NEW.description,detail=NEW.detail,after_sale=NEW.after_sale,up_time=NEW.up_time,com_image=NEW.com_image WHERE com_id=NEW.com_id; ELSIF OLD.category = 'daily_necessarity' THEN UPDATE daily_necessarity SET com_name=NEW.com_name,category=NEW.category,price=NEW.price,dis_price=NEW.dis_price,num=NEW.num, description=NEW.description,detail=NEW.detail,after_sale=NEW.after_sale,up_time=NEW.up_time,com_image=NEW.com_image WHERE com_id=NEW.com_id; ELSE UPDATE other SET com_name=NEW.com_name,category=NEW.category,price=NEW.price,dis_price=NEW.dis_price,num=NEW.num, description=NEW.description,detail=NEW.detail,after_sale=NEW.after_sale,up_time=NEW.up_time,com_image=NEW.com_image WHERE com_id=NEW.com_id; END IF;
RETURN NEW; END; $$ LANGUAGE plpgsql;
CREATE TRIGGER update_comsubtable_trigger AFTER UPDATE ON commodity FOR EACH ROW EXECUTE FUNCTION update_comsubtable_function(); DROP TRIGGER update_comsubtable_trigger ON commodity
CREATE OR REPLACE FUNCTION delete_comsubtable_function() RETURNS TRIGGER AS $$ BEGIN IF OLD.category = 'food' THEN DELETE FROM food WHERE com_id=OLD.com_id; ELSIF OLD.category = 'cloth' THEN DELETE FROM cloth WHERE com_id=OLD.com_id; ELSIF OLD.category = 'ele_appliment' THEN DELETE FROM ele_appliment WHERE com_id=OLD.com_id; ELSIF OLD.category = 'ele_product' THEN DELETE FROM ele_product WHERE com_id=OLD.com_id; ELSIF OLD.category = 'makeup' THEN DELETE FROM makeup WHERE com_id=OLD.com_id; ELSIF OLD.category = 'sport' THEN DELETE FROM sport WHERE com_id=OLD.com_id; ELSIF OLD.category = 'toy' THEN DELETE FROM toy WHERE com_id=OLD.com_id; ELSIF OLD.category = 'daily_necessarity' THEN DELETE FROM daily_necessarity WHERE com_id=OLD.com_id; ELSE DELETE FROM other WHERE com_id=OLD.com_id; END IF;
RETURN OLD; END; $$ LANGUAGE plpgsql;
CREATE TRIGGER delete_comsubtable_trigger AFTER DELETE ON commodity FOR EACH ROW EXECUTE FUNCTION delete_comsubtable_function(); DROP TRIGGER delete_comsubtable_trigger ON commodity
DROP FUNCTION calculate_price( IN product_id VARCHAR(20),IN user_id VARCHAR(20),INOUT total_payment DOUBLE PRECISION); CREATE OR REPLACE FUNCTION calculate_price( IN product_id VARCHAR(20), IN user_id2 VARCHAR(20), INOUT total_payment DOUBLE PRECISION ) AS $$ DECLARE product_price DOUBLE PRECISION; discount_price DOUBLE PRECISION; red_packet_discount DOUBLE PRECISION; red_packet_id2 INT; BEGIN SELECT price INTO product_price FROM commodity WHERE com_id = product_id; SELECT dis_price INTO discount_price FROM commodity WHERE com_id = product_id; SELECT red_packet_id INTO red_packet_id2 FROM consumer_recieve_redpacket WHERE user_id = user_id2; SELECT value_ INTO red_packet_discount FROM red_packet WHERE red_packet_id = red_packet_id2; RAISE INFO 'origin price: %', product_price; RAISE INFO 'discount_price: %', discount_price; RAISE INFO 'red_packet_discount: %', red_packet_discount; total_payment := product_price - red_packet_discount - discount_price; DELETE FROM consumer_recieve_redpacket WHERE user_id = user_id; DELETE FROM red_packet WHERE red_packet_id = red_packet_id; RETURN; END; $$ LANGUAGE plpgsql;
DROP FUNCTION buy_commodity_directly(IN product_id VARCHAR(20),IN user_id VARCHAR(20),IN order_id VARCHAR(20),IN buy_num INT); CREATE OR REPLACE FUNCTION buy_commodity_directly( IN product_id VARCHAR(20), IN user_id VARCHAR(20), IN order_id VARCHAR(20), IN buy_num INT ) RETURNS VOID AS $$ DECLARE total_payment DOUBLE PRECISION; BEGIN UPDATE commodity SET num = num - buy_num WHERE com_id = product_id; SELECT calculate_price(product_id,user_id,total_payment) INTO total_payment; INSERT INTO order_ VALUES (order_id,product_id,user_id,total_payment,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,'WAITDELIVER') ; RAISE INFO 'Calculated Total Payment: %', total_payment; RAISE INFO 'Insert order'; RAISE INFO 'update Commodity num'; END; $$ LANGUAGE plpgsql;
INSERT INTO red_packet VALUES(1,'无门槛红包',2,'无门槛','2023-12-25');
INSERT INTO consumer_recieve_redpacket VALUES ('tb12345',1); DELETE FROM order_ WHERE order_id = 'com12347tb12345'; DELETE FROM logistics WHERE com_id = 'com12347'; UPDATE commodity SET num = 1000 WHERE com_id = 'com12347';
SELECT buy_commodity_directly('com12347', 'tb12345', 'com12347tb12345', 1); SELECT * FROM order_;
SELECT * FROM commodity WHERE com_id = 'com12347'; SELECT * FROM food WHERE com_id = 'com12347'; SELECT * FROM logistics; SELECT * FROM red_packet; SELECT * FROM consumer_recieve_redpacket;
DROP FUNCTION store_launch_commodity(IN product_id VARCHAR(20),IN user_id VARCHAR(20),IN launch_num INT); CREATE OR REPLACE FUNCTION store_launch_commodity( IN product_id VARCHAR(20), IN store_id VARCHAR(20), IN launch_num INT ) RETURNS VOID AS $$ BEGIN UPDATE commodity SET num = num - launch_num WHERE com_id = product_id; INSERT INTO sell VALUES (store_id,com_id,CURRENT_TIMESTAMP) ; END; $$ LANGUAGE plpgsql;
DROP FUNCTION return_commodity(IN product_id VARCHAR(20),IN user_id VARCHAR(20),IN buy_num INT); CREATE OR REPLACE FUNCTION return_commodity( IN product_id VARCHAR(20), IN user_id VARCHAR(20), IN buy_num INT ) RETURNS VOID AS $$ DECLARE total_payment DOUBLE PRECISION; BEGIN UPDATE commodity SET num = num + buy_num WHERE com_id = product_id; UPDATE order_ SET state = 'REFUNDING' WHERE com_id = product_id AND user_id = user_id; END; $$ LANGUAGE plpgsql;
DELETE FROM users WHERE user_id = 'tb12347'; INSERT INTO users VALUES ('tb12345', 'Daming', '123456789', 'F', '13981367234', 'consumer'); INSERT INTO users VALUES ('tb12342', 'Amy', 'a123456789', 'M', '13981367555', 'consumer'); INSERT INTO users VALUES ('tb12341', 'LingLing', 'l123456789', 'M', '13221367234','consumer'); INSERT INTO users VALUES ('tb12343', 'David', 'd123456789', 'F', '13987767234', 'consumer'); INSERT INTO users VALUES ('tb12344', 'sally', 's123456789', 'M', '13984467234', 'consumer'); INSERT INTO users VALUES ('tb12347', 'Tom', 't123456789', 'F', '13984467234', 'seller'); INSERT INTO users VALUES ('tb12346', 'Jerry', 'j123456789', 'M', '13921367234', 'seller'); INSERT INTO users VALUES ('tb12348', 'Jack', 'j1234567689', 'M', '15581367234', 'seller'); INSERT INTO users VALUES ('tb12349', 'Rose', 'r123456789', 'F', '15481367234', 'seller'); INSERT INTO users VALUES ('tb12340', 'Lily', 'l123456789', 'F', '15681367234', 'seller');
ALTER TABLE consumer ALTER COLUMN headshot TYPE VARCHAR(500); INSERT INTO consumer VALUES ('tb12345', 'Daming', '123456789', 'F', '13981367234', 'T', 5, 'http://img.alicdn.com/sns_logo/i2/2212109088345/O1CN01rsPVu02BW3rihzm8e_!!2212109088345-0-ggpersonal.jpg', 0, 0, 5, 10.5, 500, '13981367234', 'consumer','com12347+1 com12348+1'); INSERT INTO consumer VALUES ('tb12342', 'Amy', 'a123456789', 'M', '13981367555', 'T', 5, 'http://img.alicdn.com/sns_logo/i2/2212109088345/O1CN01rsPVu02BW3rihzm8e_!!2212109088345-0-ggpersonal.jpg', 5, 5, 5, 20.5, 50, '13981367555', 'consumer','com12349+2 com12348+2'); INSERT INTO consumer VALUES ('tb12341', 'LingLing', 'l123456789', 'M', '13221367234', 'T', 5, 'http://img.alicdn.com/sns_logo/i2/2212109088345/O1CN01rsPVu02BW3rihzm8e_!!2212109088345-0-ggpersonal.jpg', 10, 3, 8, 30.5, 900, '13221367234', 'consumer'); INSERT INTO consumer VALUES ('tb12343', 'David', 'd123456789', 'F', '13987767234', 'T', 5, 'http://img.alicdn.com/sns_logo/i2/2212109088345/O1CN01rsPVu02BW3rihzm8e_!!2212109088345-0-ggpersonal.jpg', 10, 10, 5, 100.5, 1500, '13987767234', 'consumer'); INSERT INTO consumer VALUES ('tb12344', 'sally', 's123456789', 'M', '13984467234', 'T', 5, 'http://img.alicdn.com/sns_logo/i2/2212109088345/O1CN01rsPVu02BW3rihzm8e_!!2212109088345-0-ggpersonal.jpg', 30, 30, 9, 120.5, 2500, '13984467234', 'consumer','com12347+1');
SELECT * FROM consumer;
INSERT INTO seller VALUES ('tb12347', 'Tom', 't123456789', 'F', '13984467234', 'seller','T','T'); INSERT INTO seller VALUES ('tb12346', 'Jerry', 'j123456789', 'M', '13921367234', 'seller','T','F'); INSERT INTO seller VALUES ('tb12348', 'Jack', 'j1234567689', 'M', '15581367234', 'seller','F','T'); INSERT INTO seller VALUES ('tb12349', 'Rose', 'r123456789', 'F', '15481367234', 'seller','T','F'); INSERT INTO seller VALUES ('tb12340', 'Lily', 'l123456789', 'F', '15681367234', 'seller','T','T');
SELECT * FROM consumer; SELECT * FROM users; SELECT * FROM seller;
INSERT INTO store VALUES ('400672256','Time food','food', 'https://img.alicdn.com/imgextra/i1/O1CN01pz5irY1bhDKceJor2_!!6000000003496-2-tps-144-144.png', 'tb12346','567 West Main Street, Oakville, Canada', 1231234.23,421343,21344,67,123134,4,5,'2018-05-15',0 );
INSERT INTO store VALUES ('400672257','Fashion women wear','cloth', 'https://img.alicdn.com/imgextra/i1/O1CN01pz5irY1bhDKceJor2_!!6000000003496-2-tps-144-144.png', 'tb12347','1234 Maple Street, Springfield, USA', 141241.12,214120,12312,70,14223,3,5,'2020-01-10',0 );
INSERT INTO store VALUES ('400672258','happy toy','toy', 'https://img.alicdn.com/imgextra/i1/O1CN01pz5irY1bhDKceJor2_!!6000000003496-2-tps-144-144.png', 'tb12348','789 Elmwood Avenue, Portland, USA', 412442.2,4124,423,40,2223,2,4,'2022-09-23',0 );
INSERT INTO commodity VALUES ('com12347', 'cookie', 'food', 5.99, 1,1000,'very delicious', 'Deliciously crisp and golden, these cookies are the perfect blend of sweetness and crunch. Each bite is filled with rich flavors, leaving a lingering vanilla aroma. Indulge in these irresistible treats that will surely satisfy your cravings. Enjoy them with a cup of tea or share them with friends for a delightful snack experience.', 'Seven days no reason to return','2023-07-01', 'https://img.alicdn.com/imgextra/i3/1408820149/O1CN01B67UhV1CyHv3krMdJ_!!0-saturn_solar.jpg_460x460q90.jpg_.webp');
INSERT INTO commodity VALUES ('com12348', 'River snail rice noodle', 'food', 10.99, 0,5000,'smelly but delicious', 'A popular dish from southern China, this bowl of noodles is filled with complex flavors and textures. The slippery rice noodles are topped with a savory sauce made from pickled bamboo shoots, spicy chili oil, minced pork, and fragrant herbs. Served with vinegar and peanuts for extra zing and crunch, this dish is a must-try for any food lover.', 'Seven days no reason to return','2023-05-20', 'https://img.alicdn.com/imgextra/i1/2485630119/O1CN01XjB5ap1CkY1ioEbec_!!0-saturn_solar.jpg_460x460q90.jpg_.webp');
INSERT INTO commodity VALUES ('com12349', 'spicy strip', 'food', 0.5, 0,100000,'Taste of childhood', 'Spicy and addictive, these chewy strips pack a punch of flavor. Infused with a blend of fiery spices, they offer a satisfying kick with every bite. Whether you enjoy them as a snack on the go or as a zesty addition to your favorite dishes, these spicy sticks are sure to spice up your day.', 'Seven days no reason to return','2023-01-15', 'https://img.alicdn.com/imgextra/i4/101025137/O1CN014tAkX81nonUmjbfXL_!!0-saturn_solar.jpg_460x460q90.jpg_.webp');
INSERT INTO commodity VALUES ('com12350', 'Braised beef noodles', 'food', 3.5, 0,10000,'filling', 'Spicy and addictive, these chewy strips pack a punch of flavor. Infused with a blend of fiery spices, they offer a satisfying kick with every bite. Whether you enjoy them as a snack on the go or as a zesty addition to your favorite dishes, these spicy sticks are sure to spice up your day.', 'Seven days no reason to return','2023-10-02', 'https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/2371566698/O1CN014qvI8h1zLjhoHxwEH_!!0-item_pic.jpg_460x460q90.jpg_.webp');
INSERT INTO commodity VALUES ('com12351', 'jelly', 'food', 20.99, 5.99,10000,'chewy and delicious', 'Delightfully wobbly and bursting with fruity sweetness, this jelly treat is a playful indulgence for all ages. Each colorful, translucent cube offers a refreshing burst of flavor, making it a fun and satisfying snack. Whether enjoyed on its own or as part of a dessert, this jiggly delight is sure to bring joy.', 'Seven days no reason to return','2023-11-01', 'https://img.alicdn.com/imgextra/i3/2908500146/O1CN01UEccf61CwujVuykdl_!!0-saturn_solar.jpg_460x460q90.jpg_.webp');
INSERT INTO commodity VALUES ('com13310', 'Down jacket', 'cloth', 399, 100,2000,'Fit like a glove', 'Designed for warmth and style, this down jacket is the ultimate winter companion. Filled with soft and insulating down feathers, it provides exceptional insulation against the cold. Its sleek and quilted design offers a trendy and modern look, while the cozy hood and zippered pockets add practicality. Stay snug and fashionable in this essential winter apparel.', 'Seven days no reason to return','2023-10-20', 'https://g-search1.alicdn.com/img/bao/uploaded/i4/i2/3422193418/O1CN01BV60Ej1b7UcX4Zjyz_!!3422193418.jpg_460x460q90.jpg_.webp');
INSERT INTO commodity VALUES ('com13410', 'Midea air conditioner', 'ele_appliment', 2999, 200,2000,'Very cool', 'This air conditioner is the perfect solution for keeping your home cool and comfortable. With its powerful cooling capabilities, it quickly cools down any room. Its sleek and compact design fits seamlessly into any space, while its energy-efficient technology ensures minimal electricity consumption. Control the temperature with ease using the remote control or programmable timer, making it a convenient and reliable option for hot summer months.', 'Seven days no reason to return','2023-02-27', 'https://img.alicdn.com/imgextra/i2/100532851/O1CN01CqyVgR1Wvo3NORkOs_!!2-saturn_solar.png_460x460q90.jpg_.webp');
INSERT INTO commodity VALUES ('com13510', 'vivo mobile phone', 'ele_product', 99999, 2000,2000,'Too expensive', 'Sleek and powerful, this smartphone is a technological marvel. Its high-resolution display brings visuals to life with vibrant colors and sharp details. With a lightning-fast processor and ample storage capacity, it effortlessly handles multitasking and stores all your important files. Capture stunning photos with its advanced camera system and stay connected with fast internet speeds. This phone merges style and functionality seamlessly, making it a must-have gadget.', 'Seven days no reason to return','2023-10-27', 'https://img.alicdn.com/imgextra/i2/14867192/O1CN01mHqjjR22zzPUyJaeD_!!0-saturn_solar.jpg_460x460q90.jpg_.webp');
INSERT INTO commodity VALUES ('com13610', 'Liquid foundation', 'makeup', 49, 0,2000,'Flawless coverage, radiant complexion', 'This foundation is a game-changer. It provides seamless coverage that blurs imperfections, leaving a natural and glowing complexion. Its lightweight formula blends effortlessly, ensuring a smooth and even finish. With long-lasting staying power, it keeps your skin looking flawless all day. Enhance your beauty with this exceptional foundation.', 'Seven days no reason to return','2023-11-27', 'https://img.alicdn.com/imgextra/i1/30321366/O1CN01GuqGrB1Lxfims8RoA_!!0-saturn_solar.jpg_460x460q90.jpg_.webp');
INSERT INTO commodity VALUES ('com13710', 'Ultraman', 'toy', 20.3, 0,5000,'Children like it very much', 'Unleash your creativity with this versatile toy. With endless possibilities, it sparks imagination and promotes hands-on learning. Its durable construction ensures long-lasting fun, while its vibrant colors and unique design capture attention. Whether building, stacking, or creating imaginative stories, this toy guarantees hours of entertainment for children of all ages.', 'Seven days no reason to return','2022-12-15', 'https://g-search1.alicdn.com/img/bao/uploaded/i4/i1/1898884903/O1CN01YPWF7r1m5coIGl8h2_!!1898884903.jpg_460x460q90.jpg_.webp');
INSERT INTO food VALUES ('com12347', 'cookie', 'food', 5.99, 1,1000,'very delicious', 'Deliciously crisp and golden, these cookies are the perfect blend of sweetness and crunch. Each bite is filled with rich flavors, leaving a lingering vanilla aroma. Indulge in these irresistible treats that will surely satisfy your cravings. Enjoy them with a cup of tea or share them with friends for a delightful snack experience.', 'Seven days no reason to return','2023-07-01', 'https://img.alicdn.com/imgextra/i3/1408820149/O1CN01B67UhV1CyHv3krMdJ_!!0-saturn_solar.jpg_460x460q90.jpg_.webp', 180,'1kg','Original taste');
INSERT INTO food VALUES ('com12348', 'River snail rice noodle', 'food', 10.99, 0,5000,'smelly but delicious', 'A popular dish from southern China, this bowl of noodles is filled with complex flavors and textures. The slippery rice noodles are topped with a savory sauce made from pickled bamboo shoots, spicy chili oil, minced pork, and fragrant herbs. Served with vinegar and peanuts for extra zing and crunch, this dish is a must-try for any food lover.', 'Seven days no reason to return','2023-05-20', 'https://img.alicdn.com/imgextra/i1/2485630119/O1CN01XjB5ap1CkY1ioEbec_!!0-saturn_solar.jpg_460x460q90.jpg_.webp', 90,'225g','Original taste');
INSERT INTO food VALUES ('com12349', 'spicy strip', 'food', 0.5, 0,100000,'Taste of childhood', 'Spicy and addictive, these chewy strips pack a punch of flavor. Infused with a blend of fiery spices, they offer a satisfying kick with every bite. Whether you enjoy them as a snack on the go or as a zesty addition to your favorite dishes, these spicy sticks are sure to spice up your day.', 'Seven days no reason to return','2023-01-15', 'https://img.alicdn.com/imgextra/i4/101025137/O1CN014tAkX81nonUmjbfXL_!!0-saturn_solar.jpg_460x460q90.jpg_.webp', 360,'50g','Original taste');
INSERT INTO food VALUES ('com12350', 'Braised beef noodles', 'food', 3.5, 0,10000,'filling', 'Spicy and addictive, these chewy strips pack a punch of flavor. Infused with a blend of fiery spices, they offer a satisfying kick with every bite. Whether you enjoy them as a snack on the go or as a zesty addition to your favorite dishes, these spicy sticks are sure to spice up your day.', 'Seven days no reason to return','2023-10-02', 'https://g-search3.alicdn.com/img/bao/uploaded/i4/i1/2371566698/O1CN014qvI8h1zLjhoHxwEH_!!0-item_pic.jpg_460x460q90.jpg_.webp', 90,'225g','Braised beef');
INSERT INTO food VALUES ('com12351', 'jelly', 'food', 20.99, 5.99,10000,'chewy and delicious', 'Delightfully wobbly and bursting with fruity sweetness, this jelly treat is a playful indulgence for all ages. Each colorful, translucent cube offers a refreshing burst of flavor, making it a fun and satisfying snack. Whether enjoyed on its own or as part of a dessert, this jiggly delight is sure to bring joy.', 'Seven days no reason to return','2023-11-01', 'https://img.alicdn.com/imgextra/i3/2908500146/O1CN01UEccf61CwujVuykdl_!!0-saturn_solar.jpg_460x460q90.jpg_.webp', 360,'100g','orange');
INSERT INTO sell VALUES ('400672256','com12347','2023-08-01'); INSERT INTO sell VALUES ('400672256','com12348','2023-05-30'); INSERT INTO sell VALUES ('400672256','com12349','2023-02-18'); INSERT INTO sell VALUES ('400672256','com12350','2023-10-07'); INSERT INTO sell VALUES ('400672256','com12351','2023-11-10');
SELECT * FROM commodity; SELECT * FROM store; SELECT * FROM food; SELECT * FROM sell;
SELECT com_id FROM ((store NATURAL JOIN sell)NATURAL JOIN commodity) WHERE store_id = '400672256';
INSERT INTO message VALUES ('ms0000000000001','文本','你吃饭了吗?','2022-01-10 12:00:00'); INSERT INTO message VALUES ('ms0000000000002','文本','还没有','2022-01-10 12:00:30'); INSERT INTO message VALUES ('ms0000000000003','文本','今天布置了什么作业了?','2022-01-12 18:00:00'); INSERT INTO message VALUES ('ms0000000000004','文本','数值计算的编程作业','2022-01-12 18:30:53'); INSERT INTO message VALUES ('ms0000000000005','文本','edge detection','2022-01-12 18:44:24'); INSERT INTO message VALUES ('ms0000000000006','文本','一会去哪吃?','2022-01-10 12:00:47'); INSERT INTO message VALUES ('ms0000000000007','文本','兰园二楼','2022-01-10 12:01:20'); INSERT INTO message VALUES ('ms0000000000008','图片','D:\image\2.jpg','2022-01-12 18:50:55'); INSERT INTO message VALUES ('ms0000000000009','视频','D:\video\2.mp4','2022-01-12 18:51:56');
INSERT INTO conversation_message VALUES ('ms0000000000001','文本','你吃饭了吗?','2022-01-10 12:00:00', true); INSERT INTO conversation_message VALUES ('ms0000000000002','文本','还没有','2022-01-10 12:00:30', false); INSERT INTO conversation_message VALUES ('ms0000000000006','文本','一会去哪吃?','2022-01-10 12:00:47', false); INSERT INTO conversation_message VALUES ('ms0000000000007','文本','兰园二楼','2022-01-10 12:01:20', false);
INSERT INTO group_message VALUES ('ms0000000000003','文本','今天布置了什么作业了?','2022-01-12 18:00:00'); INSERT INTO group_message VALUES ('ms0000000000004','文本','数值计算的编程作业','2022-01-12 18:30:53'); INSERT INTO group_message VALUES ('ms0000000000005','文本','edge detection','2022-01-12 18:44:24'); INSERT INTO group_message VALUES ('ms0000000000008','图片','D:\image\2.jpg','2022-01-12 18:50:55'); INSERT INTO group_message VALUES ('ms0000000000009','视频','D:\video\2.mp4','2022-01-12 18:51:56'); DROP TABLE message; DROP TABLE group_message; SELECT * FROM message; SELECT * FROM conversation_message; SELECT * FROM group_message;
INSERT INTO evaluation VALUES ('ev0000000000001','文本','这件衣服的材质很好,穿起来很舒服', false, '好', '2023-02-22 14:00:00', false, 0, 0, 5, 5, 5, 5); INSERT INTO evaluation VALUES ('ev0000000000002','文本','这个充电宝充电慢,还会漏电', false, '差', '2023-03-12 15:30:53', false, 0, 0, 1, 1, 3, 3); INSERT INTO evaluation VALUES ('ev0000000000003','文本','这个薯片很好吃,值得一买', true, '好', '2023-04-11 08:12:22', false, 0, 0, 5, 5, 4, 5); INSERT INTO evaluation VALUES ('ev0000000000003','文本','这个薯片很好吃,值得一买', true, '好', '2023-04-11 08:12:22', false, 0, 0, 5, 5, 4, 2); INSERT INTO evaluation VALUES ('ev0000000000004','文本','这件衣服真的很好看,还便宜', false, '好', '2023-02-23 10:10:55', true, 25, 30, 5, 5, 5, 5); INSERT INTO evaluation VALUES ('ev0000000000005','图片','D:\image\1.jpg', false, '好', '2023-03-23 11:25:35', false, 10, 3, 5, 4, 4, 5); INSERT INTO evaluation VALUES ('ev0000000000006','视频','D:\video\1.mp4', false, '好', '2023-01-25 16:55:45', false, 0, 0, 5, 5, 5, 5); SELECT * FROM evaluation; DELETE FROM evaluation WHERE evaluation_id = 'ev0000000000005';
DROP TABLE evaluation;
INSERT INTO friend_and_friend VALUES ('tb12345', 'tb12342', 'ms0000000000001'); INSERT INTO friend_and_friend VALUES ('tb12342', 'tb12345', 'ms0000000000002'); INSERT INTO friend_and_friend VALUES ('tb12345', 'tb12342', 'ms0000000000006'); INSERT INTO friend_and_friend VALUES ('tb12342', 'tb12345', 'ms0000000000007'); SELECT * FROM friend_and_friend;
|