mysql grammar
清空表:TRUNCATE TABLE table_name;
防止关键字冲突:``
使用数据库:use database_name;
SQL注释:
#Comment
-- Comment
/*Comment*/
条件SET语句:/*! */
条件DDL:
- DROP TABLE IF EXISTS table_name;
- CREATE DATABASE IF NOT EXISTS database_name;
- CREATE TABLE IF NOT EXISTS ×××;
条件DML:
- INSERT IGNORE INTO table_name ×××;
- REPLACE INTO table_name ×××;
- INSERT INTO ××× ON DUPLICATE KEY UPDATE ×××;
时间:https://www.cnblogs.com/majianming/p/9647786.html
CURRENT_TIMESTAMP
andCURRENT_TIMESTAMP()
are synonyms forNOW()
.SYSDATE()
returns the time at which it executes. This differs from the behavior forNOW()
, which returns a constant time that indicates the time at which the statement began to execute. (Within a stored function or trigger,NOW()
returns the time at which the function or triggering statement began to execute.)
语句分隔符:
;
等同于\g
:查询结果横向显示\G
:查询结果纵向显示
IN与OR:
- 当条件满足时,IN使用排序后的二分查找来做筛选,效率要高于OR
https://dev.mysql.com/doc/refman/8.0/en/comparison-operators.html#operator_in
字段宽度:
- 无需为整数类型字段指定宽度,整数类型的存储宽度由类型本身决定,例如INT为4
查询重复数据/出现次数:
select column_name1,column_name2,count(*)
from table_name
group by column_name1,column_name2
having count(*)