第十二節
創建表
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);
第十二節