[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>1.多表之间的关系
1.分类
一对一人和身份证
一对多员工和部门
多对多学生和课程
2.实现关系
一对一:可以在任意一方添加唯一外键指向另一方的主键。
一对多:在多的一方建立外键,指向一的一方的主键。
多对多:需要借助第三张中间表。中间表至少包含两个字段,这两个字段作为第三张表的外键,分别指向两张表的主键。
<>多表实现的案例分析
-- 创建旅游线路分类表 tab_category -- cid 旅游线路分类主键,自动增长 -- cname 旅游线路分列名称非空,唯一。 create
table tab_category( cid int primary key auto_increment, cname varchar(100) not
null unique ); -- 创建旅游线路表tab_route -- rid 旅游线路主键,自动增长 -- rname
旅游线路名称非空,唯一,字符串100 -- price 价格;rdate 上架时间,日期类型; cid 外键,所属分类 create table
tab_route( rid int primary key auto_increment, rname varchar(100) not null
unique , price double, rdate date, rou_cid int, foreign key (rou_cid) references
tab_category(cid) -- constraint rou_cat_fk 省略,系统分配一个随机的外键约束名 ); /* 创建用户表
tab_user uid 用户主键,自增长 username 用户名100 唯一,非空 password 密码30 非空 name 真实姓名100
birthday 生日 sex 性别,定长字符串1 telephone 手机号 字符串11 email 邮箱,字符串长度100 */ create table
tab_user( uid int primary key auto_increment, username varchar(100) not null
unique , password varchar(30) not null , name varchar(100), birthday date, sex
char(1) default '男', telephone varchar(11), email varchar(100) ); /* 创建中间表
tab_favorite rid 旅游线路id,外键 date 收藏时间 uid 用户id ,外键 rid和uid
不能重复,设置复合主键,同一个用户不能收藏同一个线路两次 */ 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) );