CREATE DATABASE test;
use test;
create table student01(
id int primary key,
name varchar(20) NOT NULL unique,
gender varchar(10) default 'male'
);
SELECT * FROM student01;
INSERT INTO student01 VALUES (1,'张三','female');
INSERT INTO student01 VALUES (2, '李四','male');
INSERT INTO student01 VALUES (3,'666','male');
DESC student01;
alter table student01 add class_id int default 1;
SELECT * FROM student01;
create table class01(
class_id int primary key,
student_id int
);
alter table class01 add constraint student_idd foreign key class01(student_id) references student01(id);
DESC student01;
DESC class01;
show create table student01;
show create table class01;
alter table class01 drop foreign key student_idd;
show create table class01;
alter table student01 add age int;
INSERT INTO student01(id,name,age,class_id) VALUES(4,'xin',29,1);
SELECT * from student01;
INSERT INTO student01(id,name,age,class_id) VALUES(5,'a',30,2),(6,'b',31,3),(7,'c',31,4);
SELECT * from student01;
update student01 set id=999 where name='xin';
update student01 set age=20,gender='female' where name='666';
SELECT * from student01;
update student01 set age=17;
delete from student01 where name='666';
SELECT * from student01;
show create table class01;
delete from student01;
SELECT * from student01;