[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
数据查询语言DQL
数据操纵语言DML
数据定义语言DDL
数据控制语言DCL
1.数据查询语言DQL
数据查询语言Dor基本结构是由SELECT子句,FROM子句,WHERE子句组成的查询块:SELECT
FROM
WHERE
2.数据操纵语言DML
数据操纵语言DM主要有三种形式:
插入:工NSERT
更新:UPDATE
删除:DELETE
3.数据定义语言DDL
数据定义语言DDz用来创建数据库中的各种对象-----表、视图、索引、同义词、聚簇等如:
CREATETABLE/VIEW/ INDEX/ sYN/CLUSTER表视图索引同义词簇
DDL操作是隐性提交的!不能rollback
4.数据控制语言DCL
数据控制语言pcI用来授予或回收访问数据库的某种特权,控制数据库操纵事务发生的时间及效果,对数据库实行监视等。如:
GRANT:授权。
ROLLBACK [WORK] TO [SAVEPOINT]: 回退到某一点。回滚--ROLLBACK;回滚命令
使数据库状态回到上次最后提交的状态。其格式为:
SQL> ROLLBACK;
COMMIT [WORK]: 提交。
在数据库的插入、删除和修改操作时,只贿当务在提交到数据时才完成。在務提交前,只有操作数据库的这个人才能有权看到所做的事情,别人只有在后提交完成后才可以看到。提交数据有三种类型:显式提交、隐式提交及自动提交。分别说明这三种类型。
(1) 显式提交
用COMMIT命令直接完成的提交为显式提交。其格式为:
SQL>COMMIT;
(2)隐式提交
用SQL命令间接完成的提交为隐式提交。这些命令是:
ALTER,AUDIT,COMMENT,CONNECT,CREATE,DISCONNECT,DROP,EXIT,GPANT,NOAUDIT,QUIT,REVOKE,RENAME。
(3)自动提交
若把AUTOCOMMIT设置为ON,则在插入、修改、删除语句执行后,系统将自动进行提交,这就是自动提交。其格式为:
SQL>SET AUTOCOMMIT ON;
SQL中和%以及=和like的区别
=和like
区别:= 匹配一个精准值, like 可以匹配一个范围
_和%
区别:_ 任意匹配一个字符,% 任意匹配多个字符
count(*),count(1)与count(column)区别
ount(*)对行的数目进行计算,包含NULL
count(column)对特定的列的值具有的行数进行计算,不包含NULL值。
count()还有一种使用方式,count(1)这个用法和count(*)的结果是一样的。
性能问题
1.任何情况下SELECT COUNT(*) FROM tablename是最优选择;
2.尽量减少SELECT COUNT(*) FROM tablename WHERE COL = ‘value’ 这种查询;
3.杜绝SELECT COUNT(COL) FROM tablename WHERE COL2 = ‘value’ 的出现。
如果表没有主键,那么count(1)比count(*)快。
如果有主键,那么count(主键,联合主键)比count(*)快。
如果表只有一个字段,count(*)最快。
count(1)跟count(主键)一样,只扫描主键。count(*)跟count(非主键)一样,扫描整个表。明显前者更快一些。