A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 你岑哥哥 初级黑马   /  2019-4-4 09:22  /  919 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

CREATE TABLE contents(
c_id INT PRIMARY KEY AUTO_INCREMENT ,
c_name VARCHAR(100) NOT NULL UNIQUE);

CREATE TABLE itinerary(
i_id INT PRIMARY KEY AUTO_INCREMENT,
i_name VARCHAR(100) NOT NULL UNIQUE,
price INT NOT NULL,
TIME DATE,
c_id INT,
FOREIGN KEY (c_id) REFERENCES contents(c_id));
ALTER TABLE itinerary MODIFY price DOUBLE(8,2) NOT NULL;
ALTER TABLE itinerary ADD CONSTRAINT itinerary FOREIGN KEY (c_id) REFERENCES contents(c_id) ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE itinerary DROP FOREIGN KEY itinerary_ibfk_1;
SHOW CREATE TABLE itinerary;
ALTER TABLE itinerary DROP FOREIGN KEY itinerary;



CREATE TABLE u(
u_id INT PRIMARY KEY AUTO_INCREMENT,
u_name VARCHAR(100) NOT NULL UNIQUE,
pass VARCHAR(10) NOT NULL,
NAME VARCHAR(10) NOT NULL,
birthday DATE,
sex VARCHAR(1) NOT NULL,
telephonenumber VARCHAR(11) NOT NULL,
email VARCHAR(32)
);

CREATE TABLE favorite(
i_id INT,
u_id INT,
f_time DATE,
PRIMARY KEY(i_id,u_id),
FOREIGN KEY(i_id) REFERENCES itinerary(i_id),
FOREIGN KEY(u_id) REFERENCES u(u_id)
);
ALTER TABLE favorite ADD CONSTRAINT favorite FOREIGN KEY (i_id) REFERENCES itinerary(i_id)  ON UPDATE CASCADE
ON DELETE CASCADE;
-- alter table favorite add constraint favorite foreign key (u_id) references u(u_id) on update cascade on
-- delete cascade;
DESC favorite;
SHOW TABLES;

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马