创建数据库
user(stuid,name,pass,class,profession,dor,dor_1)
stuid是主码,class代表班级,profession代表专业名,dor代表宿舍楼号,dor_1代表宿舍号
goods(goodsid,STUid,goodsname,type,price,state)
goodsis是主码,stuid是外码,goodsname是物品名字,type是类型,state是状态,1表示已经销售出,0代表还没有销售出去
代码
/*
Navicat MySQL Data Transfer
Source Server : mysql
Source Server Version : 50513
Source Host : localhost:3306
Source Database : flea_market
Target Server Type : MYSQL
Target Server Version : 50513
File Encoding : 65001
Date: 2019-09-19 13:36:47
*/
SET FOREIGN_KEY_CHECKS=0;
– Table structure for goods
DROP TABLE IF EXISTS goods
;
CREATE TABLE goods
(
goodsid
int(11) NOT NULL AUTO_INCREMENT,
STUid
varchar(11) DEFAULT NULL,
goodsname
varchar(255) DEFAULT NULL,
type
varchar(255) DEFAULT NULL,
price
int(11) DEFAULT NULL,
state
int(11) DEFAULT NULL,
PRIMARY KEY (goodsid
),
KEY STUid
(STUid
),
CONSTRAINT STUid
FOREIGN KEY (STUid
) REFERENCES user
(STUid
)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
– Records of goods
INSERT INTO goods
VALUES (‘1’, ‘20171611607’, ‘床上桌’, ‘生活用品’, ‘25’, ‘0’);
INSERT INTO goods
VALUES (‘2’, ‘20171611607’, ‘工装裤3xl’, ‘服饰’, ‘10’, ‘0’);
INSERT INTO goods
VALUES (‘3’, ‘20171611608’, ‘java从入门到放弃’, ‘书本’, ‘5’, ‘1’);
INSERT INTO goods
VALUES (‘4’, ‘20171611607’, ‘面向对象设计’, ‘书本’, ‘10’, ‘0’);
– Table structure for user
DROP TABLE IF EXISTS user
;
CREATE TABLE user
(
STUid
varchar(11) NOT NULL DEFAULT ‘’,
name
varchar(10) DEFAULT NULL,
pass
varchar(255) DEFAULT NULL,
class
varchar(255) DEFAULT NULL,
profession
varchar(255) DEFAULT NULL,
dor
int(11) DEFAULT NULL,
dor_1
int(11) DEFAULT NULL,
PRIMARY KEY (STUid
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
– Records of user
INSERT INTO user
VALUES (‘20171611607’, ‘何佳乐’, ‘178818’, ‘1701’, ‘软件工程’, ‘18’, ‘111’);
INSERT INTO user
VALUES (‘20171611608’, ‘吕泽阳’, ‘184444’, ‘1701’, ‘软件工程’, ‘18’, ‘111’);
INSERT INTO user
VALUES (‘20171611688’, ‘乔彦玮’, ‘154522’, ‘1701’, ‘软件工程’, ‘18’, ‘111’);