abstract:用户表(user) create table `user` ( `id` int auto_in
用户表(user)
create table `user` (
`id` int auto_increment primary key,
`username` varchar(50) -- 用户姓名
);
-- 订单表(orders)
create table `orders` (
`id` int auto_increment primary key,
`price` double,
`user_id` int
);
-- 给订单表添加外键约束
alter table orders add constraint user_fk foreign key (user_id) references user(id);
-- 向user表中添加数据
insert into user values(3,'张三');
insert into user values(4,'李四');
insert into user values(5,'王五');
insert into user values(6,'赵六');
-- 向orders 表中插入数据
insert into orders values(1,1314,3);
insert into orders values(2,1314,3);
insert into orders values(3,15,4);
insert into orders values(4,315,5);
insert into orders values(5,1014,null);
---------------------
作者:如晴天-似雨天
来源:CSDN
原文:https://blog.csdn.net/puyu9714/article/details/82872984
版权声明:本文为博主原创文章,转载请附上博文链接!
Correcting teacher:天蓬老师Correction time:2019-06-05 13:13:39
Teacher's summary:可以复制网上现成的代码, 进行参考 , 但你也太不小心了吧, 连对方的版本, 还在上面放着呢......
如果你是给客户做项目, 这样的见容还在上面, 客户看到会怎么看你.....
---------------------
作者:如晴天-似雨天
来源:CSDN
原文:https://blog.csdn.net/puyu9714/article/details/82872984