Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write procedure to insert data in to the table in phpmyadmin?

I have created table as below:

student:
+----+------+-----------+--------+
|uid | name | user_name | branch |
+----+------+-----------+--------+
|    |      |           |        |
+----+------+-----------+--------+

I want to insert data in to the table using procedure.

the procedure which i wrote is:

create procedure add(in_name varchar(50),in_user_name varchar(50),in_branch varchar(50))
begin
insert into student (name,user_name,branch) values (in_name ,in_user_name,in_branch);
end;

like image 454
Harjeet Jadeja Avatar asked Feb 22 '13 06:02

Harjeet Jadeja


People also ask

How do you insert data into a procedure?

Stored Procedure to Check Insert Execute procedure window will be opened. Now for insert, we fill the data in values in the required fields. Click on the OK button. You will see a new row added to the database table.

How do you insert data into a table?

To insert records into a table, enter the key words insert into followed by the table name, followed by an open parenthesis, followed by a list of column names separated by commas, followed by a closing parenthesis, followed by the keyword values, followed by the list of values enclosed in parenthesis.

How do I add a row to a table in PHPMyAdmin?

To add records inside a database table, open the table with phpMyAdmin and click on the Insert tab. Enter the desired data in the corresponding fields and click on Go to store it. You can see the newly inserted record by clicking on the Browse tab.

How do you insert data into MySQL?

To insert data into a MySQL table, you would need to use the SQL INSERT INTO command. You can insert data into the MySQL table by using the mysql> prompt or by using any script like PHP.


2 Answers

Try this-

CREATE PROCEDURE simpleproc (IN name varchar(50),IN user_name varchar(50),IN branch varchar(50))
BEGIN
    insert into student (name,user_name,branch) values (name ,user_name,branch);
END
like image 101
Suresh Kamrushi Avatar answered Oct 07 '22 16:10

Suresh Kamrushi


# Switch delimiter to //, so phpMyAdmin will not execute it line by line.
DELIMITER //
CREATE PROCEDURE usp_rateChapter12

(IN numRating_Chapter INT(11) UNSIGNED, 

 IN txtRating_Chapter VARCHAR(250),

 IN chapterName VARCHAR(250),

 IN addedBy VARCHAR(250)

)

BEGIN
DECLARE numRating_Chapter INT;

DECLARE txtRating_Chapter VARCHAR(250);

DECLARE chapterName1 VARCHAR(250);

DECLARE addedBy1 VARCHAR(250);

DECLARE chapterId INT;

DECLARE studentId INT;

SET chapterName1 = chapterName;
SET addedBy1 = addedBy;

SET chapterId = (SELECT chapterId 
                   FROM chapters 
                   WHERE chaptername = chapterName1);

SET studentId = (SELECT Id 
                   FROM students 
                   WHERE email = addedBy1);

SELECT chapterId;
SELECT studentId;

INSERT INTO ratechapter (rateBy, rateText, rateLevel, chapterRated)
VALUES (studentId, txtRating_Chapter, numRating_Chapter,chapterId);

END //

//DELIMITER;
like image 30
Gavindra Kalikapersaud Avatar answered Oct 07 '22 18:10

Gavindra Kalikapersaud