打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
SQL 基础整理
  • SQL语句执行顺序
  1. From
  2. 表连接
  3. on连接条件,形成新的虚拟表
  4. where 筛选条件
  5. group by 生成新的结果集合  group by 分组列表
  6. having 分组后筛选
  7. select 选出显示的
  8. order by 排序
  9. limit        分页/个数限制
  • 子查询顺序

  除了exists,先执行子查询,再外查询

  exists:相关子查询,先执行外查询,再根据子查询字段进行过滤。

  • 分页查询

  limit (page-1)*size,size

  • 字符控制函数

substr('helloworld',1,5)  hello

instr('helloworld','w')      6

LPAD(salary,10,'*')        ****salary

TRIM('H' from 'Helloworld') elloworld

  • 视图应用场景
    • 多个地方用到同样的查询结果
    • 该查询结果会用的SQL语句较复杂
  • DML 表操作 无table
insert into tableName( column1,column2,...) values(值1,...)

 

update student
set age=18
where  name='hwj'

 

/* 表数据删除 */
delete
from student where age=18
/* 多表 */
delete from student s1,course c1
where s1.class=c1.class
and s1.name='mm';
# 方式2
truncate 语句
truncate table student

 

  •  DDL 管理操作,对表操作要加上字段table
# 创建
create table if not exists student(column1,...)
# 修改 字段名
Alter table student change column 旧 新字段

# 修改表名
Alter table student rename to student1

# 修改字段类型和约束
Alter table tablename modify column column_name  约束

# 添加字段
Alter table 表名 Add column 字段;

# 删除字段
Alter table 表名 drop column 字段

# 删除表
drop table if exists 表名

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Oracle 中查询字段详细信息的sql 语句
向数据库中添加或删除列的SQL ALTER TABLE 语句
oracle复制表的sql语句
MySQL中修改列名或列的数据类型
常用的SQL语句
SQL语句(五)常用语句
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服