当前位置:网站首页>MySQL Advanced Commands
MySQL Advanced Commands
2022-08-10 22:03:00 【InfoQ】
Advanced Instructions
Indexing
- Index Type
-- query index
mysql> SHOW INDEX FROM student;
-- create index
mysql> CREATE [UNIQUE|FULLTEXT] INDEX idx_student_age
-> [USING BTREE] -- Specify the index type, default B+ tree
-> ON student(age); -- Specify the index attribute
mysql> ALTER TABLE student ADD INDEX [idx_student_age](id,age);
mysql> ALTER TABLE student ADD UNIQUE [uniq_student_age](age);
mysql> ALTER TABLE student ADD FULLTEXE [ft_student_age](age);
-- deleteIndex
mysql> DROP INDEX idx_student_age ON student;
mysql> ALTER TABLE student DROP INDEX idx_student_age; Copy to clipboardErrorCopied
View
--Create View
mysql> CREATE VIEWview_student
-> AS (SELECT * FROM student);
mysql> CREATE ALGORITHM = MERGE
-> VIEW view_student
-> AS (SELECT * FROM student)
-> WITH LOCAL CHECK OPTION;
-- view structure
mysql> SHOW CREATE VIEW view_student;
-- Delete view
mysql> DROP VIEW [IF EXISTS] view_student;
-- Modify view structure (use with caution)
mysql> ALTER VIEW view_student
-> AS (SELECT * FROM student);Copy to clipboardErrorCopied
Transaction
-- Transaction Start
mysql> START TRANSACTION;
mysql> BEGIN;
-- Transaction Commit
mysql> COMMIT;
-- transaction rollback
mysql> ROLLBACK;
-- savepoint
mysql> SAVEPOINT mypoint; -- set savepoint
mysql> ROLLBACK TO SAVEPOINT mypoint; -- Rollback to savepoint
mysql> RELEASE SAVEPOINT mypoint; -- Delete savepoint Copy to clipboardErrorCopied
mysql> SET AUTOCOMMIT = 0|1; -- 0 means turn off auto-commit, 1 means turn on auto-commit.Copy to clipboardErrorCopied
Locks
--lock
mysql> LOCK TABLES student [AS alias];
--unlock
mysql> UNLOCK TABLES;Copy to clipboardErrorCopied
Trigger
- MySQL database only supportsrow-level triggers: if an INSERT statement inserts N rows of data, the statement-level triggerTriggers execute only once, row-level triggers execute N times.
- In a trigger, you can use
OLDandNEWrepresent the old and new data for the row.The delete operation is onlyOLD, and the add operation is onlyNEW.
-- view triggers
mysql> SHOW TRIGGERS;
-- create triggers
mysql> CREATE TRIGGER my_trigger
-> BEFORE INSERT -- Trigger time BEFORE/AFTER Trigger condition INSERT/UPDATE/DELETE
-> ON student -- The listening table must be a permanent table
-> FOREACH ROW -- row level trigger
-> BEGIN
-> INSERT INTO student_logs(id,op,op_time,op_id) VALUES(null,'insert',now(),new.id)
-> END;
-- delete trigger
mysql> DROP TRIGGER [schema_name.]trigger_name;
边栏推荐
- 玩转doxygen 之RT-THREAD
- LeetCode-402-移掉K位数字
- 化学制品制造业数智化供应链管理系统:建立端到端供应链采购一体化平台
- ENVI感兴趣区ROI文件由XML格式转为ROI格式
- Regular expression of shell programming and text processor
- MATLAB神经网络拟合工具箱Neural Net Fitting使用方法
- 力扣215题,数组中的第K个最大元素
- 石油化工行业商业供应链管理系统:标准化供应商管理,优化企业供应链采购流程
- Application of Spatial 3D Model Reconstruction Based on Pix4Dmapper - Spatial Analysis and Site Selection
- 流程控制结构——《mysql 从入门到内卷再到入土》
猜你喜欢

LeetCode-36-二叉搜索树与双向链表

LeetCode-402 - Remove K digits

QT笔记——QT工具uic,rcc,moc,qmake的使用和介绍

Using SylixOS virtual serial port, serial port free implementation system

camera preview process --- from HAL to OEM

黑猫带你学Makefile第13篇:Makefile编译问题合集

shell脚本循环语句for、while语句

Black cats take you learn Makefile article 13: a Makefile collection compile problem

Exploration and practice of the "zero trust" protection and data security governance system of the ransomware virus of Meichuang Technology

管理员必须知道的RADIUS认证服务器的部署成本
随机推荐
变量和它的特性——《mysql 从入门到内卷再到入土》
shell编程之免交互
web逆向之丁香园
2022.8.9 Mock Competition
ThreadLocal全面解析(一)
How to translate financial annual report, why choose a professional translation company?
ACM模板笔记:最长不下降/上升子序列
DELETE:删除操作语法&使用例——《mysql 从入门到内卷再到入土》
C. Rotation Matching
The perfect alternative to domestic Gravatar avatars Cravatar
ArcGIS自动随机生成采样点的方法
DDL:视图——《mysql 从入门到内卷再到入土》
深度学习之 12 循环神经网络RNN2
UPDATE:修改数据语法使用例——《mysql 从入门到内卷再到入土》
B. Same Parity Summands
RADIUS Authentication Server Deployment Costs That Administrators Must Know
Interpretation of the paper (g-U-Nets) "Graph U-Nets"
接口测试的概念、目的、流程、测试方法有哪些?
labelme - block drag and drop events
黑猫带你学Makefile第12篇:常见Makefile问题汇总