MYSQL练习题

通过所提供的E-R图和数据库模型图完成库表的创建,并插入适量的数据.要求必须使用SQL命令进行构建。完成后截图提交。

MYSQL练习题_第1张图片MYSQL练习题_第2张图片MYSQL练习题_第3张图片MYSQL练习题_第4张图片MYSQL练习题_第5张图片

create table userInfo (

customerID   INT   NOT NULL AUTO_INCREMENT COMMENT '客户编号',

customerName  CHAR(50)   NOT NULL COMMENT '开户名',

PID CHAR(18) NOT NULL  COMMENT '身份证',

telephone CHAR(11) NOT NULL  COMMENT '联系电话',

address VARCHAR(255) NULL    COMMENT '居住地址',

PRIMARY KEY (customerID) USING BTREE,

UNIQUE INDEX customerName(customerName) USING BTREE

)ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;







CREATE TABLE deposit (

savingID   INT  NOT NULL AUTO_INCREMENT COMMENT '存款类型号',

savingName  VARCHAR(50)  NOT NULL COMMENT '存款类型名称',

descrip  VARCHAR(50) NULL  COMMENT '描述',

PRIMARY KEY (savingID)  

)ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;

CREATE TABLE cardInfo(

cardID char(18) NOT NULL COMMENT '卡号',

savingID INT  NOT NULL COMMENT '存款类型',

openDate TIMESTAMP(0)  NOT NULL  DEFAULT CURRENT_TIMESTAMP COMMENT '开户日期',

 openMoney   DECIMAL(10,2)  NOT NULL DEFAULT 1.00 COMMENT '开户金额',

balance   DECIMAL(10,2)  NOT NULL DEFAULT 1 COMMENT '余额',

password  VARCHAR(6)  NOT NULL DEFAULT '888888' COMMENT '密码',

IsReportLoss BIT(1) NOT NULL DEFAULT 0 COMMENT '是否挂失',

customerID  INT NOT NULL COMMENT '客户编号',

PRIMARY KEY (cardID),

FOREIGN KEY(savingID) REFERENCES deposit(savingID) ,

FOREIGN KEY(customerID) REFERENCES userInfo(customerID) 

) ENGINE = InnoDB  CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;





CREATE TABLE tradeInfo(

transDate  TIMESTAMP(0)  NOT NULL  DEFAULT CURRENT_TIMESTAMP COMMENT '交易日期',

cardID  char(18) NOT NULL COMMENT '卡号',

transType  CHAR(50) NOT NULL   COMMENT '交易类型',

transMoney   DECIMAL(10,2) NOT NULL COMMENT '交易金额',

remark  TEXT(255) NULL    COMMENT '备注',

FOREIGN KEY(cardID) REFERENCES cardInfo(cardID) 

)ENGINE = InnoDB  CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;



依次往各自表中插入数据

INSERT  INTO  `userInfo` VALUES (1,'张三',111111111111111111,12345678911,'重庆');

INSERT  INTO  `userInfo` VALUES (2,'李四',222222222222222222,12345678912,'重庆');

INSERT  INTO  `userInfo` VALUES (3,'王五',333333333333333333,12345678913,'广州');



INSERT INTO `deposit` VALUES (1,'活期存款','');

INSERT INTO `deposit` VALUES (2,'定期存款','一年以后取');



INSERT INTO `cardInfo` VALUES (11,1,'2024-01-23','88.12','44.11',111111,0,1);

INSERT INTO `cardInfo` VALUES (22,2,'2024-01-23','70.12','64.11',222222,0,1);

INSERT INTO `cardInfo` VALUES (33,2,'2024-01-23','60.11','44.95',333333,0,1);





INSERT INTO `tradeInfo` VALUES ('2024-01-23 19:42:30',11,'转账',44.01,'收到请发消息');

INSERT INTO `tradeInfo` VALUES ('2024-01-23 20:11:42',22,'转账',6.01,'收到请发消息');

INSERT INTO `tradeInfo` VALUES ('2024-01-23 20:07:33',33,'转账',15.16,'');







MYSQL练习题_第6张图片

你可能感兴趣的:(mysql,android,数据库)