I have an Insert stored procedure where I am inserting into 2 tables. The second table using the Last_Insert_ID of the first table. Here is my sproc:
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `new_user_create`(
IN oFarmName varchar(45),
IN oFirstName varchar(45),
IN oAddress1 varchar(45),
IN oCity varchar(45),
IN oState varchar(45),
IN oZip varchar(45),
IN oCountry varchar(45)
)
BEGIN
insert into intelliair.individual
( FarmName, FirstName)
values ( oFarmName, oFirstName);
insert into intelliair.address
(IndividualID, Address1, City, State, Zip, Country)
Values (Last_Insert_ID(), oAddress1, oCity, oState, oZip, oCountry);
END
Here is how I am testing the query in MySql workbench:
call new_user_create(@myFarm, @MyName, @MyAddress, @MyCity, @MyState, @MyZip, @MyCountry)
There error I get is: “Column Address1 cannot be null”
Where am I going wronng? Is it in the sproc? Or the way I am calling it?
“Column Address1 cannot be null” indicates that the
intelliair.address.Address1field must be definednot null.And, I don’t think that you pre defined value for
@MyAddressbefore passing it to the stored procedure.Unless defined it is treated as
NULLand hence is the error thrown.To cross check values before calling the stored procedure like :
Update 1:
You can call stored procedure by directly inputting values for each of the parameters.
Example: