Database Articles

Page 269 of 547

How can we drop a MySQL stored procedure?

Daniol Thomas
Daniol Thomas
Updated on 22-Jun-2020 402 Views

If we have ALTER ROUTINE privileges for the procedure then with the help of DROP PROCEDURE statement we can drop a MySQL stored procedure. To demonstrate it, we are dropping a stored procedure named ‘coursedetails’ as follows −mysql> DROP PROCEDURE coursedetails; Query OK, 0 rows affected (0.68 sec)The above query will drop the procedure named ‘coursedetails’. It can be confirmed by running the statement SHOW CREATE PROCEDURE which will return an error because the procedure does not exist.

Read More

How can we alter a MySQL stored procedure?

Prabhas
Prabhas
Updated on 22-Jun-2020 990 Views

If we have ALTER ROUTINE privileges for the procedure then with the help of ALTER PROCEDURE statement we can alter a MySQL stored procedure. To demonstrate it we are taking an example of a stored procedure named ‘delete_studentinfo’ which have the following create a statement −mysql> SHOW CREATE PROCEDURE Delete_studentinfo\G *************************** 1. row *************************** Procedure: Delete_studentinfo sql_mode: ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION Create Procedure: CREATE DEFINER=`root`@`localhost` PROCEDURE `Delete_studentinfo`( IN p_id ...

Read More

How can I use MySQL INTERVAL() function with a column of a table?

Swarali Sree
Swarali Sree
Updated on 22-Jun-2020 504 Views

We can use INTERVAL() function with a column of a table by providing the first argument as the name of the column. In this case, al the values in that column would be compared with the values given as the other arguments of INTERVAL() function and on that basis of comparison, the result set is provided. To understand it, the data from the employee table is used which is as follows −mysql> Select* from employee568; +----+--------+--------+ | ID | Name   | Salary | +----+--------+--------+ | 1  | Gaurav | 50000  | | 2  | Rahul  | 20000  | | ...

Read More

How can I get all the records of a table by passing its name as the parameter of MySQL stored procedure?

V Jyothi
V Jyothi
Updated on 22-Jun-2020 395 Views

Suppose if we want to see all the records of a table by passing its name as the parameter of a stored procedure then following example will create a procedure named ‘details’ which accepts the name of the table as its parameter −mysql> DELIMITER // mysql> Create procedure details(tab_name Varchar(40))    -> BEGIN    -> SET @t:= CONCAT('Select * from', ' ', tab_name);    -> Prepare stmt FROM @t;    -> EXECUTE stmt;    -> END // Query OK, 0 rows affected (0.00 sec)Now invoke this procedure by giving the name of the table as its parameter and it will ...

Read More

How can we perform START transactions inside MySQL stored procedure?

Sreemaha
Sreemaha
Updated on 22-Jun-2020 521 Views

As we know the START transaction will start the transaction and set the auto-commit mode to off. In the following example, we have created a stored procedure with a START transaction which will insert a new record in table employee.tbl having the following data −mysql> Select * from employee.tbl; +----+---------+ | Id | Name    | +----+---------+ | 1  | Mohan   | | 2  | Gaurav  | | 3  | Rahul   | +----+---------+ 3 rows in set (0.00 sec)Examplemysql> Delimiter // mysql> Create Procedure st_transaction()    -> BEGIN    -> START TRANSACTION;    -> INSERT INTO employee.tbl(name) values ...

Read More

Create a MySQL stored procedure, which takes the name of the database as its parameter, to list the tables with detailed information in a particular database.

Sravani S
Sravani S
Updated on 22-Jun-2020 598 Views

Suppose currently we are using a database named ‘query’ and it is having the following tables in it −mysql> Show tables in query; +-----------------+ | Tables_in_query | +-----------------+ | student_detail | | student_info | +-----------------+ 2 rows in set (0.00 sec)Now, following is a stored procedure, which will accept the name of the database as its parameter and give us the list of tables with detailed information −mysql> DELIMITER// mysql> CREATE procedure tb_list(db_name varchar(40)) -> BEGIN -> SET @z := CONCAT('Select * from information_schema.tables WHERE table_schema = ', ''', db_name, ...

Read More

How can a MySQL stored procedure call another MySQL stored procedure inside it?

Vrundesha Joshi
Vrundesha Joshi
Updated on 22-Jun-2020 4K+ Views

It is quite possible that a MySQL stored procedure can call another MySQL stored procedure inside it. To demonstrate it, we are taking an example in which a stored procedure will call another stored procedure to find out the last_insert_id.Examplemysql> Create table employee.tbl(Id INT NOT NULL AUTO_INCREMENT, Name Varchar(30) NOT NULL, PRIMARY KEY(id))// Query OK, 0 rows affected (3.87 sec) mysql> Create Procedure insert1()    -> BEGIN insert into employee.tbl(name) values ('Ram');    -> END// Query OK, 0 rows affected (0.10 sec)Now, in the next procedure insert2() we will call the 1st stored procedure i.e. insert1().mysql> Create Procedure insert2() ...

Read More

What MySQL returns if the first argument of INTERVAL() function is NULL?

Kumar Varma
Kumar Varma
Updated on 22-Jun-2020 190 Views

MySQL returns -1 as output if the first argument of INTERVAL() function is NULL. Following example will demonstrate it −mysql> Select INTERVAL(NULL, 20, 32, 38, 40, 50, 55); +--------------------------------------+ | INTERVAL(NULL, 20, 32, 38, 40, 50, 55) | +--------------------------------------+ | -1 | +--------------------------------------+ 1 row in set (0.00 sec)It will return -1 even if any of the other arguments is NULL along ...

Read More

Why is it good to write the numbers in MySQL INTERVAL() function in ascending order?

Chandu yadav
Chandu yadav
Updated on 22-Jun-2020 165 Views

Actually, INTERVAL() function uses the binary search for searching the bigger number than the number at first argument. So, that is why if we want INTERVAL() function to work efficiently the list of numbers would be in ascending order. Following is a good way to use INTERVAL() function −mysql> Select INTERVAL(50,20,32,38,40,50,55);

Read More

What MYSQL INTERVAL() function returns if there is no bigger number in the list of arguments than the number at first argument?

Akshaya Akki
Akshaya Akki
Updated on 22-Jun-2020 170 Views

In this case, MySQL INTERVAL() function returns the index number of the last number in argument list plus 1. In other words, the last index number in the list plus 1 would be returned by this function. Following example will demonstrate it −mysql> Select INTERVAL(50,20,32,38,40); +--------------------------+ | INTERVAL(50,20,32,38,40) | +--------------------------+ | 4 | +--------------------------+ 1 row in set (0.00 sec)

Read More
Showing 2681–2690 of 5,468 articles
« Prev 1 267 268 269 270 271 547 Next »
Advertisements