Baeilfire
Baeilfire

Reputation: 1

stored procedures trying to insert into two tables: error 1136

Im trying to get this program to add a new row into two different tables: bilde and student. The values entered into bilde should come from the values used in student.

At this point i get this message: error code: 1136. Column count dosen't match value at row 1, and im not quite sure what to do to fix this.

DELIMITER $$ 
DROP PROCEDURE IF EXISTS NyStudent $$

CREATE PROCEDURE NyStudent (
                        brukernavn VARCHAR(45)
                        ,fornavn VARCHAR(45)
                        ,etternavn VARCHAR(45)
                        ,klassekode INT
                        )

BEGIN
    START TRANSACTION;
    INSERT INTO bilde (filnavn, beskrivelse)
        VALUES (CONCAT('bilder/', fornavn, '.jpg'), CONCAT('bilde av ', fornavn, ' ', etternavn));
    INSERT INTO student
        VALUES ('donaldduck','donald','duck','1');
    COMMIT;
END$$ 

DELIMITER ;
CALL NyStudent('donaldduck','donald','duck','1');

Upvotes: -1

Views: 52

Answers (1)

sabhari karthik
sabhari karthik

Reputation: 1371

Try adding the column names in the 'INSERT INTO' statement for students, as that should be the major reason for column count error.

Also, Even when we insert values for every column of the table, it is a best practice to include column names after INSERT INTO statement. Following this would avoid any breakage in code to a certain extent, even on schema changes in the future.

Upvotes: 0

Related Questions