当前位置:网站首页>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
OLD
andNEW
represent 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;
边栏推荐
- 2022.8.9 模拟赛
- 管理员必须知道的RADIUS认证服务器的部署成本
- ArcMap创建镶嵌数据集、导入栅格图像并修改像元数值显示范围
- LeetCode-36-Binary search tree and doubly linked list
- Common interview questions for APP UI automation testing, maybe useful~
- INSERT:插入操作语法&使用例——《mysql 从入门到内卷再到入土》
- Intelligent scheme design - intelligent rope skipping scheme
- MATLAB神经网络拟合工具箱Neural Net Fitting使用方法
- shell programming without interaction
- FPGA - 7系列 FPGA内部结构之Memory Resources -03- 内置纠错功能
猜你喜欢
shell (text printing tool awk)
PROCEDURE :存储过程结构——《mysql 从入门到内卷再到入土》
元宇宙社交应用,靠什么吸引用户「为爱发电」?
着力提升制造业核心竞争力,仪器仪表产业迎高质量发展
Service - DNS forward and reverse domain name resolution service
xshell (sed command)
带你一文读懂SaaS版多租户商城系统对多品牌企业的应用价值
直播课堂系统09--腾讯云点播管理模块(一)
LeetCode-36-Binary search tree and doubly linked list
[SQL brush questions] Day3----Special exercises for common functions that SQL must know
随机推荐
DDL:视图——《mysql 从入门到内卷再到入土》
Common interview questions for APP UI automation testing, maybe useful~
着力提升制造业核心竞争力,仪器仪表产业迎高质量发展
3D model reconstruction of UAV images based on motion structure restoration method based on Pix4Dmapper
Play RT-THREAD of doxygen
使用 Cloudreve 搭建私有云盘
快消品行业经销商协同系统:实现经销商可视化管理,提高沟通执行效率
美创科技勒索病毒“零信任”防护和数据安全治理体系的探索实践
关于 DataFrame: 处理时间
如何保护 LDAP 目录服务中的用户安全?
ArcMap创建镶嵌数据集、导入栅格图像并修改像元数值显示范围
HGAME 2022 Week2 writeup by pankas
Likou 221 questions, the largest square
shell脚本循环语句for、while语句
Black cat takes you to learn Makefile Part 12: Summary of common Makefile problems
Object.assign用法 以及 与$.extend的区别
Redis 性能影响 - 异步机制和响应延迟
C. Rotation Matching
shell小技巧(一百三十五)打包指定目录下所用文件,每个文件单独打包
DDL:ALTER 修改数据库——《mysql 从入门到内卷再到入土》