MySQL与SQL的触发器的不同写法_MySQL
bitsCN.com
触发器经常用于加强数据的完整性约束和业务规则等。在MySQL与SQL操作中经常会用到,下文中国就为大家讲述MySQL与SQL的触发器的不同写法,希望对大家能够有所帮助。
触发器作用:
当在SQL、MySQL数据库中一张表中插入一条记录时,触动触发器,使同一数据库的另一张表插入相同记录。
在学习的过程中,发现两者的写法是不同的。
1、在SQL中建立两张表sql_test,sql_tem。(两张表的字段是一样的)
复制代码 代码如下:
create table sql_test
(
id int,
name varchar(16)
)
create table sql_tem
(
id int,
name varchar(16)
)
复制代码 代码如下:
/*SQL的触发器写法*/
create trigger insert_sql_test on sql_test
for insert
as
insert into sql_tem
select * from inserted
go
/*SQL的触发器写法*/
2、在MySQL中建立两张表mysql_test,mysql_tem。(两张表的字段是一样的,建表语句与上面的类似)
复制代码 代码如下:
/*MySQL的触发器写法*/
delimiter//
create trigger insert_mysql_test before insert on test
for each row
begin
insert into tem set id = new id , name = new name;
/*new后面的id,name是test表的字段名*/
end
//
关于MySQL与SQL的触发器的不同写法就为大家总结出来这么多,这些经验都是细心人士从平时的工作中总结出的,所以啊,还需要大家在工作中细心去发现,会有意想不到的惊喜哦。
bitsCN.com
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to hide text before any click in PowerPoint If you want text to appear when you click anywhere on a PowerPoint slide, setting it up is quick and easy. To hide text before clicking any button in PowerPoint: Open your PowerPoint document and click the Insert menu. Click on New Slide. Choose Blank or one of the other presets. Still in the Insert menu, click Text Box. Drag a text box onto the slide. Click the text box and enter your

How to write triggers in MySQL using PHP MySQL is a commonly used relational database management system, and PHP is a popular server-side scripting language. Using PHP to write triggers in MySQL can help us realize automated database operations. This article will introduce how to use PHP to write MySQL triggers and provide specific code examples. Before starting, make sure that MySQL and PHP have been installed and the corresponding database tables have been created. 1. Create PHP files and data

In Oracle database, you can use the CREATE TRIGGER statement to add triggers. A trigger is a database object that can define one or more events on a database table and automatically perform corresponding actions when the event occurs.

How to write custom triggers and stored procedures in MySQL using PHP Introduction: When developing applications, we often need to perform some operations at the database level, such as inserting, updating, or deleting data. MySQL is a widely used relational database management system, and PHP is a popular server-side scripting language. This article will introduce how to write custom triggers and stored procedures in MySQL using PHP, and provide specific code examples. 1. What are triggers and stored procedure triggers (Trigg

MySQL triggers are row-level. According to SQL standards, triggers can be divided into two types: 1. Row-level triggers, which will be activated once for each row of data modified. If a statement inserts 100 rows of data, the trigger will be called 100 times; 2. Statement-level triggers The trigger is activated once for each statement. A statement that inserts 100 rows of data will only call the trigger once. MySQL only supports row-level triggers, not prepared statement-level triggers.

How to write custom triggers in MySQL using Python Triggers are a powerful feature in MySQL that can define some automatically executed operations on tables in the database. Python is a concise and powerful programming language that can easily interact with MySQL. This article will introduce how to write custom triggers using Python and provide specific code examples. First, we need to install and import the PyMySQL library, which is Python's way of working with a MySQL database

How to write custom stored procedures, triggers and functions in MySQL using C# MySQL is a widely used open source relational database management system, and C# is a powerful programming language for development tasks that require interaction with the database. Say, MySQL and C# are good choices. In MySQL, we can use C# to write custom stored procedures, triggers and functions to achieve more flexible and powerful database operations. This article will guide you in using C# to write and execute

How to use MySQL triggers to implement automatic archiving of data Introduction: In the field of modern data management, automatic archiving and cleaning of data is an important and common requirement. As the amount of data increases, retaining complete historical data will occupy excessive storage resources and reduce query performance. MySQL triggers provide an effective way to achieve this requirement. This article will introduce how to use MySQL triggers to achieve automatic archiving of data. 1. What is a MySQL trigger? A MySQL trigger is a special kind of memory.
