search
HomeDatabaseMysql TutorialMySQL学习笔记4-触发器、MySQL视图_MySQL

bitsCN.com

MySQL触发器 创建只有一个执行语句的触发器基本形式:

CREATE TRIGGER 触发器名 BEFORE | AFTER 触发事件

ON 表名 FOR EACH ROW 执行语句创建具有多个执行语句的触发器

基本形式:

CREATE TRIGER 触发器名称 BEFORE | AFTER 触发事件

ON 表名 FOR EACH ROW

BEGIN

执行语句列表

END注意:在MySQL中,一个表在相同的时间和相同的触发时间只能创建一个触发器,如触发事件INSERT,触发时间AFTER的触发器只能有一个,但是可以定义BEFORE的触发器。查看触发器 SHOW TRIGGERS;SELECT * FROM information_schema.triggers;

或者:SELECT * FROM information_schema.triggers WHERE TRIGGER_NAME='触发器名称';

information_schema是MySQL中默认存在的库,用于记录触发器信息的数据表。应用触发器
触发器中不能包含START TRANSCATION、COMMIT或ROLLBACK等关键词,也不能包含CALL语句。删除触发器

DROP TRIGGER 触发器名称

MySQL视图 视图是一个虚表,是从数据库中一个或多个表中导出来的表,其内容由查询定义。数据库中只存放了视图的定义,没有存放视图中的数据。视图中的数据是依赖于原来的表中的数据的。视图是存储在数据库中的查询的sql语句,它主要出于安全和可使复杂的查询易于理解和 使用。视图作用: 简单性安全性逻辑数据独立性 创建视图 查看用户是否具有创建视图的权限

select select_priv,create_view_priv from mysql.user where user='用户名';

创建视图

CREATE [ALGORITHM={UNDEFINDE | MERGE | TEMPTABLE}]

VIEW 视图名 [(属性清单)]

AS SELECT 语句

[WITH [CASCADED | LOCAL] CHECK OPTION];创建视图注意事项 有创建视图的权限select语句不能包含from子句中的子查询;select语句不能引用系统或用户变量select语句不能引用预处理语句参数在存储子程序内,定义不能引用子程序参数或局部变量在定义中引用的表或视图必须存在。在定义中不能引用temporary表,不能创建temporary视图;视图定义中命名的表必须存在不能将触发器与视图关联在一起在视图定义中允许使用order by,但是,如果从特定视图进行选择,而该视图使用了具有自己order by的语句,它将被忽略 查看视图 DESCRIBE/DESC 视图名;SHOW TABLE STATUS LIKE ‘视图名’; 修改视图 CREATE OR REPLACE [ALGORITHM={UNDEFINDE | MERGE | TEMPTABLE}]

VIEW 视图 [(属性清单)]

AS SELECT 语句

[WITH [CASCADED | LOCAL] CHECK OPTION]ALTER 更新视图 视图中的数据虽然可以更新,但是有很多的限制。一般情况下,最好将视图作为查询数据的虚拟表,而不要通过视图更新数据。删除视图 DROP VIEW IF EXISTS [RESTRICT | CASCADE]

bitsCN.com
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.