有以下MySQL代码,SET FOREIGN_KEY_CHECKS = 0; DROP TABLE IF EXISTS employee_info; CREATE TABLE employee_info ( e_id int(0) NOT NULL COMMENT '工作人员编号', e_name varchar(50) NOT NULL COMMENT '工作人员姓名', m_id int(0) NOT NULL COMMENT '管理员编号', PRIMARY KEY (e_id) USING BTREE, INDEX m_id(m_id) USING BTREE, CONSTRAINT m_id FOREIGN KEY (m_id) REFERENCES hotel_manager_info (m_id) ON DELETE CASCADE ON UPDATE CASCADE ) ; DROP TABLE IF EXISTS hotel_info; CREATE TABLE hotel_info ( h_id int(0) NOT NULL COMMENT '酒店序号', h_name varchar(25) NOT NULL COMMENT '酒店名称', h_address varchar(255) NOT NULL COMMENT '酒店地址', h_phone varchar(50) NOT NULL COMMENT '酒店电话', o_statistics int(0) NULL DEFAULT NULL COMMENT '统计订单量', PRIMARY KEY (h_id) USING BTREE ) ; DROP TABLE IF EXISTS hotel_manager_info; CREATE TABLE hotel_manager_info ( m_id int(0) NOT NULL COMMENT '管理员编号', m_name varchar(50) NOT NULL COMMENT '管理员姓名', h_id int(0) NULL DEFAULT NULL COMMENT '酒店序号', PRIMARY KEY (m_id) USING BTREE, INDEX hotel_id(h_id) USING BTREE, CONSTRAINT hotel_id FOREIGN KEY (h_id) REFERENCES hotel_info (h_id) ON DELETE CASCADE ON UPDATE CASCADE ) ; DROP TABLE IF EXISTS order_info; CREATE TABLE order_info ( o_id int(0) NOT NULL COMMENT '订单编号', r_id int(0) NOT NULL COMMENT '房间号', u_id int(0) NOT NULL COMMENT '用户id', o_checkin_time datetime(0) NULL DEFAULT NULL COMMENT '入住时间', o_checkout_time datetime(0) NOT NULL COMMENT '离开时间', o_status enum('not null','null') NULL DEFAULT NULL COMMENT '为null 时表示未入住', PRIMARY KEY (o_id) USING BTREE, INDEX r_id(r_id) USING BTREE, INDEX u_id(u_id) USING BTREE, CONSTRAINT r_id FOREIGN KEY (r_id) REFERENCES room_info (r_id) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT u_id FOREIGN KEY (u_id) REFERENCES user_info (u_id) ON DELETE CASCADE ON UPDATE CASCADE ) ; DROP TABLE IF EXISTS room_info; CREATE TABLE room_info ( r_id int(0) NOT NULL COMMENT '房间号', r_name varchar(50) NOT NULL COMMENT '房间名称', r_type varchar(50) NOT NULL COMMENT '房间类型', r_price varchar(50) NULL DEFAULT NULL COMMENT '房间价格', h_id int(0) NOT NULL COMMENT '酒店序号', PRIMARY KEY (r_id) US
时间: 2024-04-02 20:31:40 浏览: 117
rdb.rar_if
这是一段 MySQL 代码,用于创建四个表:employee_info(员工信息表),hotel_info(酒店信息表),hotel_manager_info(酒店管理员信息表),order_info(订单信息表),和一个 room_info(房间信息表)的外键。其中,hotel_manager_info表和hotel_info表之间建立了外键关系,employee_info表和hotel_manager_info表之间建立了外键关系,order_info表和user_info表以及room_info表之间建立了外键关系。使用SET FOREIGN_KEY_CHECKS = 0;可以关闭MySQL的外键检查,DROP TABLE IF EXISTS则是当表存在时才会删除表。
阅读全文