操作词汇简介
insert:用于向表中插入新记录
delete:用于从表中删除记录
update:用于修改表中已有的记录
selete:用于从表中查询数据
建表
create table stu(
字段名 类型 [ 约束 ] [ 主键 ] [注释]
);
create table stu(
id bigint primary key auto_increment comment '标识符',
name varchar(100) not null comment '学生名称',
age int not null check(age between 18 and 100) comment '学生年龄',
sex char(1) not null comment '学生性别'
);
id是字段名,bigint是类型,primary key是约束,auto_increment是主键,comment是注释
增加数据
如果主键是自增的,那么主键的值可以不写,会自动生成
单个增加
如:insert into stu(列段1,列段2,列段3) values(值1,值2,值3);
查询
select 列段 from 表名;
查询的列段如果是*就是查询所有列段:
select * from student;
后面跟条件,比如年龄大于18:
select * from student where age>18;
删除
删除没有*
delete from 表名 where 条件;
删除id为1的数据
delete from student where id=1;
修改
update 表名 set 列名 = 值 where 条件;
update student set name='李世豪',age=20 where id=1;