- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to write MySQL procedure to insert data into a table?
To write stored procedure to insert data into a table, at first you need to create a table −
mysql> create table insertDataUsingStoredProcedure -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY , -> Name varchar(20), -> Age int -> ); Query OK, 0 rows affected (0.51 sec)
Following is the query to write stored procedure to insert data into the table −
mysql> DELIMITER // mysql> CREATE PROCEDURE StoredProcedureInsertData(IN StudentName varchar(100),IN StudentAge int) -> BEGIN -> insert into insertDataUsingStoredProcedure(Name,Age) values (StudentName, StudentAge ); -> END -> // Query OK, 0 rows affected (0.13 sec) mysql> DELIMITER ;
Following is the query to call the above stored procedure to insert data into the table −
mysql> call StoredProcedureInsertData('Chris',24); Query OK, 1 row affected (0.18 sec)
Now check the data has been inserted into the table or not −
mysql> select * from insertDataUsingStoredProcedure;
This will produce the following output −
+----+-------+------+ | Id | Name | Age | +----+-------+------+ | 1 | Chris | 24 | +----+-------+------+ 1 row in set (0.00 sec)
Advertisements