数据库(sql)常用命令(2)

DML语句(数据库操作语言)

1.insert(添加语句/插入语句):

语法:insert into 表名 values (字段1,字段2,字段3,………)

示例1:insert into  student (id,name,……) values(10,’詹华’,…….);

示例2:插入多条:insert into  student (id,name,……) values(10,’詹华’,…….),(20,’张三’,…….)

2.update(更新数据语句/修改)

语法:update 表名 set 字段名 [where 条件]

示例:update student set name=’詹六’  where id=10;

3.delete(删除数据语句)

语法:delete  from 表名 [where 条件语句/]

示例:delete from student where id=10;

4.truncate(清空表数据)

语法:truncate 表名

示例:truncate student

注意:truncate 用于完全清空表数据 , 但表结构 , 索引 , 约束等不变。

DQL语句(数据库查询语言)(关键字 select) 1.1

::select语句执行顺序
from 查询表 —-》join 表连接 ——-> on 过滤条件 ——》where 过滤条件 ——》group by
进行分组 —–》 having 过滤条件 ——-》 order by 进行排序 ——》 select 选择列显示

1.查寻整个表的数据:

示例: select * from student [这个*指代全部数据]

2.查询表中某个字段:where 关键字(指定的)

示例:select *from student where sno=10;

2.1:where查询条件。

2.1.1:and  或  &&  (表示并且的意思,需要满足这左右两边的条件)

语法:select *  from 表名 where  字段条件

示例1:select *from  score where degree=>60 &°ree<=80;

示例2:select *from  score where degree=>60 and degree<=80;

2.1.2: bewten….and….(与2.1.1效果相同)

示例:select*from score where degree  bewten  60  and  80;

2.1.3: or 或 ||   (表示或者的意思)

示例1:select*from score where degree>60  or  class=’95033′;

示例2:select *from  score where degree>60 || class=’95033′;

2.1.4: not 或 !  (!取反)

示例1:select *from score where not degree=80

示例2:select *from score where degree !=80

文章知识点与官方知识档案匹配,可进一步学习相关知识MySQL入门技能树SQL高级技巧CTE和递归查询31341 人正在系统学习中

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年8月6日
下一篇 2022年8月6日

相关推荐