1. 删表

DROP TABLE IF EXISTS 表名;

  1. 新建表 create table 表名( 字段名 类型 约束(逐渐,非空,唯一 ,默认值), 字段名 类型 约束(逐渐,非空,唯一 ,默认值), )编码,存储引擎; 约束 NOT NULL:非空 UNIQUE:保证该列的唯一性 PRIMARY KEY:主键,确保某列有唯一标识符

  2. 插入 insert into 表名(字段1,字段2) values(值1,值2)

  3. 删除

delete from 表名 where id="" 5.更新

update 表名 set 字段=值(需要更新的信息) where id=“”

  1. 查询

    select * from 表名 在实际开发中,尽量不要使用*号,用字段,会增加资源消耗,效率较低

  2. 分页查 select * from 表名 Limit 2,3 //limit 2,3 表示从第2条开始查询,第3条结束 distinct关键字 select distinct 字段1 from 表名 表示查询出的结果不重复的

  3. 排序 select * from 表名 order by 字段1 asc(降序desc) like模糊查询、通配符 %表示0个或多个字符 _表示一个字符

  4. like表示模糊查询 like 后面跟字段或字段与通配符组成的字符串

  5. in 匹配多个条件 select * from 表名 where 字段1 in (值1,值2 ,值3) 表示字段1满足值1,值2,值3的条件查询的结果

  6. as:用来声明别名 列别名 表别名

  7. 两表或多表查询 join:内联 left join 左连接 right join 右连接 select * from 表1 别名1(t1) right join 表2 别名2(t2) where t1.字段1=t2.字段2

posted on 2022-09-25 22:50  吃饱饱没烦恼  阅读(22)  评论(0编辑  收藏  举报