多表关系-案例
-- 创建旅游线路分类表 tab_categore -- cid 旅游限度分类主键,自动增长 -- cname旅游线路分类名称非空,唯一 字符串100 CREATE TABLE tab_category( cid INT PRIMARY KEY auto_increment, cname VARCHAR(100) NOT NULL UNIQUE ); -- 创建旅游线路表 tab_route CREATE TABLE tab_route( rid INT PRIMARY KEY auto_increment, rname VARCHAR(100) NOT NULL UNIQUE, price DOUBLE, rdate DATE, cid INT, FOREIGN KEY (cid) REFERENCES tab_category(cid) ); -- 用户表 CREATE TABLE tab_user( uid INT PRIMARY KEY NOT NULL, username VARCHAR(100) NOT NULL, password VARCHAR(30) NOT NULL, NAME VARCHAR(100), birthday DATE, sex CHAR(1) DEFAULT '男', telephone VARCHAR(11), email VARCHAR(100) ); -- 收藏表 tab_favorite CREATE TABLE tab_favorite( rid INT, date DATETIME, uid INT, -- 创建复合主键 PRIMARY KEY(rid,uid), -- 联合主键 FOREIGN KEY(rid) REFERENCES tab_route(rid), FOREIGN KEY(uid) REFERENCES tab_user(uid) );
标签:关系,VARCHAR,KEY,--,案例,tab,多表,100,INT From: https://www.cnblogs.com/yuzong/p/16778980.html