数据操作
2、删
格式:delete from 表名 where 条件;
示例:delete from student where id=4;
注意:没有条件是全部删除,慎用!
3、改
格式:update 表名 set 列1=值1, 列2=值2, … where 条件;
示例:update student set age=16 where id=7;
注意:没有条件是全部的列修改,慎用!
4、查
格式:select * from 表名;
示例:select * from student;
说明:查询表中的全部数据
①基本语法
格式:select * from 表名;
说明:
a、from关键字后面是表名,表示数据来源于这张表
b、select后面写表中的列名,如果是 * 表示在结果集中显示表中的所有列
c、在select后面的列名部分,可以使用 as 为列 起别名,这个别名显示在结果集中
d、如果要查询多个列,之间使用逗号分隔
示例:
select * from student;
select name, age from student;
select name as a, age from student;
②消除重复行
在select后面列前面使用distinct可以消除重复的行(只留不同)
示例:
select gender from student;
select distinct gender from student;
③条件查询
a、语法
select * from 表名 where 条件
b、比较运算符
等于 =
大于 >
小于 <
大于等于 >=
小于等于 <=
不等于 !=或<>
需求:查询id值大于8的所有数据
示例:select * from student where id>8;
c、逻辑运算符
and 并且
or 或者
not 非
需求:查询id值大于7的女同学
示例:select * from student where id>7 and gender=0;
先插入3条数据
insert into student values(0, "李白", 18, 1, "北京", 0), (0, "李信", 18, 1, "武汉", 0), (