Found 4219 Articles for MySQLi

How can we check the list of all triggers in a database?

Manikanth Mani
Updated on 22-Jun-2020 11:52:21

147 Views

With the help of the SHOW TRIGGERS statement, we can list all the triggers in a particular database. It can be illustrated with the help of the following example −Examplemysql> Show Triggers\G *************************** 1. row ***************************   Trigger: trigger_before_delete_sample     Event: DELETE     Table: sample Statement: BEGIN SET @count = if (@count IS NULL, 1, (@count+1)); INSERT INTO sample_rowaffected values (@count); END   Timing: BEFORE  Created: 2017-11-21 12:31:58.70 sql_mode: ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERR OR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION              Definer: root@localhost character_set_client: cp850 collation_connection: cp850_general_ci   Database Collation: latin1_swedish_ci *************************** 2. ... Read More

How can we get the summary output of a column in MySQL result set itself?

Anvi Jain
Updated on 22-Jun-2020 11:46:57

443 Views

We can get the summary output of a column in MySQL result set by using the “WITH ROLLUP” modifier. This modifier is used with GROUP BY CLAUSE. It gives the summary output to include extra rows that represent higher-level summary operations.ExampleIn this example, the WITH ROLLUP modifier gave the summary output with total cost value in the extra row.mysql> Select Item_name, SUM(Cost) AS Total_cost from Item_list GROUP BY Item_name WITH ROLLUP; +-----------+------------+ | Item_name | Total_cost | +-----------+------------+ | Notebook  | 45.00      | | Pen       | 31.70      | | Pencilbox | 125.20     | | NULL      | 201.90     | +-----------+------------+ 4 rows in set (0.00 sec)

What is the meaning of ‘empty set’ in MySQL result set?

Nitya Raut
Updated on 22-Jun-2020 11:53:16

4K+ Views

If there is ‘empty set’ in the result set of MySQL query then it means that MySQL is returning no rows and no error also in the query. It can be understood with the help of the following example −mysql> Select * from Student_info WHERE Name = 'ABCD'; Empty set (0.00 sec)We can see the empty set and execution time as output. It means that the query is correct but the MySQL table is not having the name ‘ABCD’.

What are the advantages, disadvantages and restrictions of using MySQL triggers?

Fendadis John
Updated on 22-Jun-2020 11:50:53

4K+ Views

We must have to understand the advantages, disadvantages, and restrictions of using MySQL triggers so that we can use it effectively.AdvantagesFollowings are the advantages of using MySQL triggers −Integrity of data − With the help of MySQL trigger we can check the integrity of data in the table. In other words, MySQL triggers are the alternative way to check the integrity of data.Useful for catching errors − MySQL triggers can catch errors in business logic in the database layer.Alternative way to run scheduled tasks − Actually by using MySQL triggers we do not have to wait to run the scheduled tasks because ... Read More

How can we discard a MySQL statement in the middle of its processing?

Prabhas
Updated on 22-Jun-2020 11:51:28

55 Views

With the help of \c command, we can discard a MySQL statement in the middle of its processing. Consider the following example in which in the middle of the statement we want to discard it then we use \c option for it −mysql> Select *    -> from\c mysql>The above query shows that after using \c option MySQL discards the statement and returns to the prompt.

How can SELECT, without reference to any table, be used to calculate expression in MySQL?

Govinda Sai
Updated on 22-Jun-2020 11:49:51

64 Views

With the help of following MySQL statement, we can use SELECT to calculate the expression −SELECT expression;The above statement is having no reference to any table. Followings are some examples −mysql> Select 10 DIV 5; +----------+ | 10 DIV 5 | +----------+ |        2 | +----------+ 1 row in set (0.06 sec) mysql> Select 10*5; +------+ | 10*5 | +------+ |   50 | +------+ 1 row in set (0.00 sec) mysql> Set @var1 = 100, @var2 = 200; Query OK, 0 rows affected (0.00 sec) mysql> Select @Var1+@Var2; +-------------+ | @Var1+@Var2 | +-------------+ |         300 | +-------------+ 1 row in set (0.00 sec)

How does ‘FOR EACH ROW’ work in the MySQL trigger?

Samual Sam
Updated on 22-Jun-2020 11:54:52

4K+ Views

Actually ‘FOR EACH ROW’ means for each of the matched rows that get either updated or deleted. In other words, we can say that trigger is not applied to each row, it just says to execute the trigger body for each affected table row. We can illustrate this by the following example −ExampleIn this example, we are creating two tables, Sample and Sample_rowaffected, as follows −mysql> Create table Sample(id int, value varchar(20)); Query OK, 0 rows affected (0.47 sec) mysql> Insert into Sample(id, value) values(100, 'same'), (101, 'Different'), (500, 'excellent'), (501, 'temporary'); Query OK, 4 rows affected (0.04 sec) ... Read More

What is the use of ‘c’ option while writing MySQL statements?

Ramu Prasad
Updated on 22-Jun-2020 11:40:20

325 Views

‘\c’ option means ‘clear’ and is used to clear the current input. Suppose if we do not want to execute a command that we are entering, then we can use a clear \c option which clears the current input. For example, the use of \c option can be done as follows −mysql> Select *     -> from\cIn the example above, when we use \c in a statement, MySQL clears the current input and returns back to the MySQL prompt for accepting other statements.

How MySQL evaluates the statement written on different lines?

Jennifer Nicholas
Updated on 22-Jun-2020 11:53:48

61 Views

Actually, MySQL determines the end of the statement when it got termination semicolon. Suppose if we are writing a single statement in different lines then after writing the first line, MySQL changes promptly from ‘mysql>’ to ‘->’ which indicates that MySQL has not seen a complete statement yet and is waiting for the rest. When it got semicolon then MySQL executes the statement. It can be understood with the help of the following example −Examplemysql> Select Id, Name     -> From     -> Student_info     -> ; +------+---------+ | Id   | Name    | +------+---------+ ... Read More

How can we use MySQL SELECT without FROM clause?

Sravani S
Updated on 22-Jun-2020 11:42:35

1K+ Views

FROM clause after SELECT shows the references to a table. But if there is no reference to any table then we can use SELECT without the FROM clause. In other words, we can say that SELECT can be used to retrieve rows computed without reference to any table. Consider the following statements −mysql> Select concat_ws(" ","Hello", "World"); +---------------------------------+ | concat_ws(" ","Hello", "World") | +---------------------------------+ | Hello World                     | +---------------------------------+ 1 row in set (0.00 sec) mysql> Set @var1=100; Query OK, 0 rows affected (0.00 sec) mysql> Select @var1; +-------+ | @var1 | +-------+ |   100 | +-------+ 1 row in set (0.00 sec)

Advertisements