Home Database Mysql Tutorial Comparison of the use of triggers in Oracle and the use of triggers in mysql

Comparison of the use of triggers in Oracle and the use of triggers in mysql

Jan 18, 2017 am 11:08 AM

Mysql relational database management system

MySQL is an open source small relational database management system developed by the Swedish MySQL AB company. MySQL is widely used in small and medium-sized websites on the Internet. Due to its small size, fast speed, low total cost of ownership, and especially the characteristics of open source, many small and medium-sized websites choose MySQL as their website database in order to reduce the total cost of website ownership.


This article mainly introduces the case comparison of Oracle's use of triggers and mysql's use of triggers. This article explains it through examples and gives you a very detailed introduction. Friends who need it Refer to the following

1. Triggers

1. Triggers are stored as independent objects in the database,

2. Triggers do not need to be called, they are An event triggers the operation

 3. Triggers cannot receive parameters

 --Trigger application

 For example: Xiaonei.com, Kaixin.com, Facebook, when you Post a log and automatically notify friends. In fact, when adding a log, you make a start and then write entries to the table.

 --The efficiency of triggers is very high

For example: For forum postings, every time a post is inserted, you want to synchronize the last posting time and total number of posts fields in the forum table. At this time Using triggers will be very efficient.

2. Oracle uses PL/SQL to write triggers

1.--General syntax for creating triggers in PL/SQL

create [or replace] trigger trigger_name
{before | after}
{insert | delete | update [of column[,column ... ]]} on table_name
[for each row]
[where condition]
--trigger_body;
begin 
end;
Copy after login

2.--Exercise

--问题3.使用:old 和 :new 操作符
create or replace trigger tri_update
after
update on employees
for each row 
begin
  dbms_output.put_line('更新前:'||:old.salary||' 更新后:'||:new.salary);
end;
--问题2.编写一个触发器,在向 emp 表中插入记录时 打印'hello'
create or replace trigger tri_update
after
insert on emp
begin
  dbms_output.put_line('ok');
end;
--问题1.一个helloworld级别的触发器
--创建一个触发器,在更新employees表的时候触发
create or replace trigger tri_update
after
update on employees
for each row --想在最后执行完打印一个ok,把这句话去掉
begin
  dbms_output.put_line('ok');
end;
--执行
update employees
set salary = salary+1
where department_id = 80
Copy after login

3. Using triggers in MySql

--假设有两张表 board 和 article
create table board(
  id int primary key auto_increment,
  name varchar(50),
  articleCount int
);
create table article(
  id int primary key auto_increment,
  title varchar(50),
  bid int references board(id)
);
--创建一个触发器
delimiter $$
create trigger insertArticle_trigger 
after insert on article 
for each row
begin
  update board set articleCount=articleCount+1
where id = new.bid;
end;
$$
delimiter ;
--当我们对article表执行插入操作的是后就会触发这个触发器
insert into board values(null,'test_boardname',0);
insert into article values(null,'test_title',1);
--执行完这条插入语句后,board表中的articleCount字段值回+1;这个操作由触发器完成。
Copy after login

The above is the comparison of cases of using triggers in Oracle and using triggers in mysql. For more related content, please pay attention to the PHP Chinese website (www.php. cn)!


Statement of this Website
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

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 Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1657
14
PHP Tutorial
1257
29
C# Tutorial
1230
24
MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

MySQL for Beginners: Getting Started with Database Management MySQL for Beginners: Getting Started with Database Management Apr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles