修改表中字段得名字
alter tale 表名 change 旧的字段名 新的字段名 修饰符;
例子: 将phone 字段名字改成 mobile
alter table student change phone mobile char(11);
给表格添加 字段
alter table 表名 add 字段名 修饰符 ;
例子: 给 student 表 添加 phone 字段
alter table student add phone char(11) not null;
一般来说 表格一旦建立,不会轻易更改字段,如果已有2000w记录
删除表格中得字段
alter table 表名 drop 字段名;
例子: 将 student表中 多余字段 mobile 删除
alter table student drop mobile;
插入单条数据以及多条
插入数据
往表格中插入数据;
insert 表名(需要填写的字段) values(根据前面的字段进行设置);
不规定插入的字段, 按表格字段整个填入;
insert student values(‘4’,‘hanmeimei’,‘18’,‘F’),(‘5’,‘lisi’,‘52’,default);
修改表中得数据
update 表名 set 字段=修改 指定哪条记录; 一定要指定修改哪条记录,否则会全部修改;
例子:
update student set name=‘xiaoli’ where id=5;
#将 将第5条数据的姓名改为 xiaoli
update student set gender=‘f’ where name=‘xiaoli’;
#将小红的 性别改为女
查询数据
select * from 表名;
- 显示表中所有的字段;
- 例子:
select * from students;
select age,name 表名;
只挑选年龄和姓名字段;
【去重 distinct】
select distinct 字段 from 表名,
将挑选出字段的 重复数据去除
age字段中有是三个 20岁只会显示1个20岁
例子:
select distinct age from students;
条件查询(where)
select “字段” from"表名" where “条件”;
select age from students where ><= 或or 且and between;
where 后面 可以跟上 > < = org and between
例子:
找出大于20岁的人
select name,age from students where age>20;
找出20岁的人
select name,age from students where age=20;
找出小于20岁的人
select name,age from students where age<20;
找出20岁到50岁之间的人
select name,age from students where age>20 and age<50 ;
select name,age from students where age between 20 and 50;