-
创建表:
create table 表名(字段名 数据类型 约束,字段名 数据类型 约束…)
其中约束包含是否为主键、外键、是否自动增长、是否为空、是否唯一、默认值、是否大于某个值等等create table person(_id Integer primary key, name varchar(10), age Integer not null)
-
删除表
drop table 表名drop table person
-
插入数据
insert into 表名[字段1,字段2…] values(值1,值2…)insert into person(_id,age) values(1,20) insert into person(2,"小明",18)
-
修改数据
update 表名 set 字段1 = 新值1, 字段2 = 新值2 where 修改条件update person set name"XiaoMing", age=20 where _id=1
-
删除数据
delete from 表名 where 删除条件delete from person where _id=1
批量删除数据
delete from person where _id in (1, 2, 3)
-
查询语句
select 字段名 from 表名 where 查询条件 group by 分组的字段 having 筛选条件 order by 排序字段# 查询一个表中的所有数据 select * from person # 查询表中的所有_id和name的字段 select _id,name from person # 查询_id=1的数据 select * from person where _id=1 # 查询_id不等于1的数据 select * from person where _id<>1 # 查询_id等于1且age大于10的数据 select * from person where _id=1 and age>10 # 查询名字中包含“小”的数据 select * from person where name like "%小%" # 查询名字中第二个字符为“小”的数据 select * from person where name like "_小%" # 查询名字为空的数据 select * from person where name is null # 查询年龄在10到20之间的数据 select * from person where age between 10 and 20 # 查询年龄大于18的数据,并按照_id排序 select * from person where age>18 order by _id
常用SQL语句
于 2020-01-05 11:37:12 首次发布