Found 4219 Articles for MySQLi

What is MySQL event and how it is related to trigger?

Alankritha Ammu
Updated on 22-Jun-2020 12:19:01

450 Views

A MySQL event is a task that rums based on a predefined schedule therefore sometimes it is referred to as a scheduled event. In other words, we can say that the MySQL event schedule is a process that runs in the background and constantly looks for the events to execute. It is referred to as a temporal trigger because they triggered by time and not like triggers that execute based on the table update. We can use events to run either once or at a recurring interval. They can be used to create backups, delete stale records, aggregate data for ... Read More

How can we create a MySQL one-time event that executes immediately?

Lakshmi Srinivas
Updated on 22-Jun-2020 12:20:40

497 Views

As we know a one-time event means the events that will be executed only once on a particular schedule. To illustrate the creation of such kind of events we are using the following example in which we are creating an event which will execute at the current time −Examplemysql> Create table event_message(ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, MESSAGE VARCHAR(255) NOT NULL, Generated_at DATETIMENOT NULL); Query OK, 0 rows affected (0.61 sec) mysql> CREATE EVENT testing_event ON SCHEDULE AT CURRENT_TIMESTAMP DO INSERT INTO event_message(message, generated_at) Values('Hello', NOW()); Query OK, 0 rows affected (0.00 sec) mysql> Select * from ... Read More

How can we compare data in two MySQL tables?

Prabhas
Updated on 14-Feb-2020 11:09:29

1K+ Views

Sometimes we need to identify the unmatched data from two tables, especially in the case when data is migrated. It can be done by comparing the tables. Consider the example below in which we have two tables named ‘students’ and ‘student1’.mysql> Select * from students; +--------+--------+----------+ | RollNo | Name   | Subject  | +--------+--------+----------+ |    100 | Gaurav | Computer | |    101 | Raman  | History  | |    102 | Somil  | Computer | +--------+--------+----------+ 3 rows in set (0.00 sec) mysql> select * from student1; +--------+--------+----------+ | RollNo | Name | Subject | ... Read More

How will GROUP BY clause perform without an aggregate function?

Krantik Chavan
Updated on 22-Jun-2020 12:31:12

4K+ Views

When we use GROUP BY clause in the SELECT statement without using aggregate functions then it would behave like DISTINCT clause. For example, we have the following table −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Chandigarh | Literature | | 125  | Raman   | Shimla     | Computers  | | 130  | Ram     | Jhansi     | Computers  | | 132  | Shyam   | Chandigarh ... Read More

When a MySQL arithmetic expression returns NULL?

seetha
Updated on 22-Jun-2020 12:19:41

80 Views

As we know that a NULL is not a value and it is also not the same as zero. MySQL arithmetic expression returns NULL if we will use NULL in it. It can be understood with the help of the following example −Examplemysql> Select 100*NULL; +----------+ | 100*NULL | +----------+ |     NULL | +----------+ 1 row in set (0.00 sec) mysql> Select 100+NULL; +----------+ | 100+NULL | +----------+ |     NULL | +----------+ 1 row in set (0.00 sec)From the above example, it can be observed that if we will use NULL in an arithmetic expression then the result would be NULL itself.

How can we enter BOOLEAN values in MySQL statement?

Anvi Jain
Updated on 22-Jun-2020 12:20:04

358 Views

As we know that there is no BOOLEAN data type in MySQL hence by using TRUE or true, FALSE or false we can enter Boolean values in MySQL statement.Examplemysql> Select TRUE,FALSE; +------+-------+ | TRUE | FALSE | +------+-------+ | 1    | 0     | +------+-------+ 1 row in set (0.00 sec) mysql> Select true,false; +------+-------+ | TRUE | FALSE | +------+-------+ | 1    | 0     | +------+-------+ 1 row in set (0.00 sec)

How can we enter numerical values as a BINARY number in MySQL statement?

vanithasree
Updated on 22-Jun-2020 12:21:32

69 Views

Following are the two approaches with the help of which we can enter numeric values as a BINARY number −By prefix ‘B’In this approach we need to quote binary numbers within single quotes with a prefix of B. Then BINARY number string will be automatically converted into a numerical value based on the expression context.Examplemysql> Select B'1110'+0; +-----------+ | B'1110'+0 | +-----------+ |        14 | +-----------+ 1 row in set (0.00 sec)By prefix 0bIn this approach, we need to write BINARY numbers without any quotes with a prefix of 0b. Then BINARY number string will be automatically ... Read More

How can we enter characters as a BINARY number in MySQL statement?

Smita Kapse
Updated on 22-Jun-2020 12:22:22

133 Views

Following are the two approaches with the help of which we can enter characters as a BINARY number −By prefix ‘B’In this approach we need to quote binary numbers within single quotes with a prefix of B. Then BINARY number string will be automatically converted into a character string.Examplemysql> Select B'01000001'; +-------------+ | B'01000001' | +-------------+ | A           | +-------------+ 1 row in set (0.00 sec)By prefix 0bIn this approach, we need to write BINARY numbers without any quotes with a prefix of 0b. Then BINARY number string will be automatically converted into a character ... Read More

How can we see the information on triggers order in case of multiple triggersfor same event and action time?

karthikeya Boyini
Updated on 22-Jun-2020 12:12:28

63 Views

It can be done with the help of the following query −mysql> SELECT trigger_name,action_order FROM INFORMATION_SCHEMA.triggers WHERE TRIGGER_SCHEMA = 'query' ORDER BY event_object_table,action_timing,event_manipulation; +------------------------------+--------------+ | trigger_name                 | action_order | +------------------------------+--------------+ | studentdetail_before_update  |            1 | | studentdetail_before_update2 |            2 | +------------------------------+--------------+ 2 rows in set (0.10 sec)The above result set shows the order of multiple triggers created on the same event and action time in the database ‘query’.

How is it possible for a MySQL trigger to execute multiple statements?

George John
Updated on 30-Jul-2019 22:30:21

673 Views

The MySQL trigger can execute multiple statements with the help of BEGIN…END construct. Within the BEGIN block, we can also use another syntax that is permitted within stored routines such as conditionals and loops. For illustrating the concept, we are using the following example of BEFORE INSERT TRIGGER is having the IF conditional statements − Example mysql> Create Trigger before_inser_studentage BEFORE INSERT ON student_age FOR EACH ROW BEGIN IF NEW.age < 0 THEN SET NEW.age = 0; ELSEIF NEW.age > 100 THEN SET NEW.age = 100; END IF; END // Query OK, 0 rows affected (0.30 sec)

Advertisements