1.建表
create table student
(
Sno char(9) PRIMARY KEY,
Sname char(20) UNIQUE,
Sage int,
);
注:建表时的级联操作,当再建一个表senior_stu参照了student表的Sno字段时,可以选择级联(CASCADE)删除或者更新,也就是student表中Sno=1的元组删除或更新时,senior_stu表中参照student中Sno=1的字段也一起删除或者更新;当选了限制(RESTRICT)操作时,student表中的字段就不能单独随便删除或者更新。
2.查询
select * from student;
select Sno,Sname from student;
select * from student where Sno='200220121';
select count(*) from student;
select * from student limit 1,3;从第二条记录开始查,连续查三条
select * from student limit 0,4;从第一条记录开始查,连续查四条
3.插入
insert into student values('200220122','张三',14);
insert into student(Sno,Sname,Sage) values('200220122','张三',14);
在插入时当表中的某个字段设置为自增长或者是有默认值,就可以在执行插入操作时不管这些字段,当插入时这些字段自动的赋上了默认值。
4.更新
update student set Sage=22 where Sno='200220123';
update student set Sage=Sage+1;
5.删除
delete from student where Sno='200220124';
delete from student;
---------------------------------------------分界线------------------------------------------------------
create table student
(
Sno char(9) PRIMARY KEY,
Sname char(20) UNIQUE,
Sage int,
);
注:建表时的级联操作,当再建一个表senior_stu参照了student表的Sno字段时,可以选择级联(CASCADE)删除或者更新,也就是student表中Sno=1的元组删除或更新时,senior_stu表中参照student中Sno=1的字段也一起删除或者更新;当选了限制(RESTRICT)操作时,student表中的字段就不能单独随便删除或者更新。
2.查询
select * from student;
select Sno,Sname from student;
select * from student where Sno='200220121';
select count(*) from student;
select * from student limit 1,3;从第二条记录开始查,连续查三条
select * from student limit 0,4;从第一条记录开始查,连续查四条
3.插入
insert into student values('200220122','张三',14);
insert into student(Sno,Sname,Sage) values('200220122','张三',14);
在插入时当表中的某个字段设置为自增长或者是有默认值,就可以在执行插入操作时不管这些字段,当插入时这些字段自动的赋上了默认值。
4.更新
update student set Sage=22 where Sno='200220123';
update student set Sage=Sage+1;
5.删除
delete from student where Sno='200220124';
delete from student;
---------------------------------------------分界线------------------------------------------------------