首页 > 其他 > 详细

第十二节

时间:2017-11-10 14:55:49      阅读:265      评论:0      收藏:0      [点我收藏+]

创建表

create table student(
 `id` int not null primary key auto_increment,
 `name` char(32));

插入数据
insert into student(name) values (‘pan‘);
insert into student(name) values (‘zhang‘);

技术分享


添加字段

alter table `student` add column stu_id int not null default 0 after name;删除字段

alter table `student` drop column stu_id;

修改字段

update student set stu_id=9001 where id=1;

创建第二张表

create table study_record(
 `id` int not null primary key auto_increment,
 `day` int(11) not null,
 `status` char(32) not null,
 `stu_id` int(11) not null,
 key `fk_student_key` (`stu_id`),
 constraint `fk_student_key` foreign key (`stu_id`) references `student` (id)  #主外键更多的是某表的主键与子表的某个列进行关联,要求是具备相同的数据类型和属性
 );

插入数据

insert into study_record (day,status,stu_id) values (01,‘yes‘,1);

insert into study_record (day,status,stu_id) values (01,‘no‘,2);

技术分享

 

第十二节

原文:http://www.cnblogs.com/ttyypjt/p/7814189.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!