创建新数据库:create database 数据库名
修改数据库:alter database
创建新表:create table
变更(改变)数据库表:alter table
删除表:drop table
增加一条记录:
insert into 表名 (列名1,列名2,列名3...) values (值1,值2,值3...);
删除一条记录:
delete from 表名 ;
delete from 表名 where 条件 ;
修改一条记录:
update 表名 set 列名 = 值 , 列名 = 值 ; //表中所有记录的字段都修改了
update 表名 set 列名 = 值 , 列名 = 值 where 条件; //该条件的那一行的列名的值被修改了
查询一条记录:
select * from 表名;
select * from 表名 where 条件;
select * from user where name like '李%';//在user表中查找name字段中姓“李”的学生
select * from user order by id desc; //在user表中记录按id降序排序(desc)。默认是升序(asc)
select * from user where birthday between '19930101' and '19931231';//使用between...and..查找范围内的记录
between:
操作符 between... and会选取介于两个值之间的数据范围。这些值可以是数值、文本或者日期。
使用and、or组合可以查找出1993年出生的学生,使用between同样可以,而且更简洁:
select * from students where birthday >= '19930101' and birthday <= '19931231';//使用and
select * from students where birthday between '19930101' and '19931231';//使用between。显然此方式更简洁