当前位置:网站首页>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;
边栏推荐
- Service - DNS forward and reverse domain name resolution service
- MATLAB神经网络拟合工具箱Neural Net Fitting使用方法
- Likou 221 questions, the largest square
- B. Codeforces Subsequences
- UPDATE:修改数据语法使用例——《mysql 从入门到内卷再到入土》
- 力扣221题,最大正方形
- shell脚本循环语句for、while语句
- HighTec shortcut keys (Keys) setting location
- Shell programming specification and variables
- unusual understanding
猜你喜欢
HighTec快捷键(Keys)设置位置
Redis Performance Impact - Asynchronous Mechanisms and Response Latency
QT笔记——QT工具uic,rcc,moc,qmake的使用和介绍
财务年报怎样翻译,为什么要选择专业翻译公司?
【SQL刷题】Day3----SQL必会的常用函数专项练习
HighTec shortcut keys (Keys) setting location
为什么一般公司面试结束后会说「回去等消息」,而不是直接告诉面试者结果?
Conditional Statements of Shell Programming (2)
shell programming without interaction
使用 Cloudreve 搭建私有云盘
随机推荐
C # Hex file transfer skills necessary article 】 【 bin file code implementation
ThreadLocal全面解析(一)
web逆向之丁香园
服务——DNS正向反向域名解析服务
Future与CompletableFuture
变量和它的特性——《mysql 从入门到内卷再到入土》
测试4年感觉和1、2年时没什么不同?这和应届生有什么区别?
PPT的两个实用技巧
Shell 编程--Sed
Using SylixOS virtual serial port, serial port free implementation system
直播课堂系统08-腾讯云对象存储和课程分类管理
What are the concepts, purposes, processes, and testing methods of interface testing?
HighTec快捷键(Keys)设置位置
Uniapp编译后小程序的代码反编译一些思路
wget编译升级故障解决
C. Even Picture
xshell (sed 命令)
DELETE:删除操作语法&使用例——《mysql 从入门到内卷再到入土》
数字化转型:如何引导创新领导者
黑猫带你学Makefile第12篇:常见Makefile问题汇总