当前位置:网站首页>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;
边栏推荐
- 基于Pix4Dmapper的空间三维模型重建应用——空间分析选址
- 【PCBA方案】电子握力测试仪方案she‘ji
- Live Classroom System 08 Supplement - Tencent Cloud Object Storage and Course Classification Management
- camera preview process --- from HAL to OEM
- c语言之 练习题1 大贤者福尔:魔法数,神奇的等式
- Conditional Statements of Shell Programming (2)
- CGO Preliminary Cognition and Basic Data Type Conversion
- UPDATE:修改数据语法使用例——《mysql 从入门到内卷再到入土》
- GAN CFOP
- What are the concepts, purposes, processes, and testing methods of interface testing?
猜你喜欢

带你一文读懂SaaS版多租户商城系统对多品牌企业的应用价值

LeetCode-36-Binary search tree and doubly linked list

FPGA - Memory Resources of 7 Series FPGA Internal Structure -03- Built-in Error Correction Function

Conditional Statements of Shell Programming (2)

shell脚本

从斐波那契 - 谈及动态规划 - 优化

RADIUS Authentication Server Deployment Costs That Administrators Must Know

These must-know JVM knowledge, I have sorted it out with a mind map

LeetCode-402-移掉K位数字

我的世界整合包 云服务器搭建方法(ECS)
随机推荐
labelme-屏蔽拖拽的事件
The perfect alternative to domestic Gravatar avatars Cravatar
F. Binary String Reconstruction
Future与CompletableFuture
什么是Jmeter?Jmeter使用的原理步骤是什么?
PROCEDURE :存储过程结构——《mysql 从入门到内卷再到入土》
关于 DataFrame: 处理时间
How to translate financial annual report, why choose a professional translation company?
Bedtime story | made a Bitmap and AST length system configuration
Black cats take you learn Makefile article 13: a Makefile collection compile problem
如何保护 LDAP 目录服务中的用户安全?
数字化转型:如何引导创新领导者
unusual understanding
直播课堂系统08-腾讯云对象存储和课程分类管理
LeetCode-36-Binary search tree and doubly linked list
Using SylixOS virtual serial port, serial port free implementation system
ENVI自动生成地面控制点实现栅格影像的自动地理配准
labelme-5.0.1版本编辑多边形闪退
ENVI最小距离、最大似然、支持向量机遥感影像分类
【SQL刷题】Day3----SQL必会的常用函数专项练习