常用SQL语句

  1. 创建表:
    create table 表名(字段名 数据类型 约束,字段名 数据类型 约束…)
    其中约束包含是否为主键、外键、是否自动增长、是否为空、是否唯一、默认值、是否大于某个值等等

    create table person(_id Integer primary key, name varchar(10), age Integer not null)
    
  2. 删除表
    drop table 表名

    drop table person
    
  3. 插入数据
    insert into 表名[字段1,字段2…] values(值1,值2…)

    insert into person(_id,age) values(1,20)
    insert into person(2,"小明",18)
    
  4. 修改数据
    update 表名 set 字段1 = 新值1, 字段2 = 新值2 where 修改条件

    update person set name"XiaoMing", age=20 where _id=1
    
  5. 删除数据
    delete from 表名 where 删除条件

    delete from person where _id=1
    

    批量删除数据

    delete from person where _id in (1, 2, 3)
    
  6. 查询语句
    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
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

得食猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值