Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

test a stored procedure in MySql Workbench

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?

like image 551
EB. Avatar asked Jul 17 '12 15:07

EB.


People also ask

How can we test stored procedure?

In SQL Server, we can test a stored procedure in different ways. For example, we can test the performance of a stored procedure using the SQL Server Profiler. Similarly, we can test the execution time of a stored procedure. And we can also test a stored procedure by checking their execution status.

How can I tell if a stored procedure is working?

You can see anything running in SQL Server using sys. dm_exec_requests dmv. It captures everything not only stored procedures.


1 Answers

"Column Address1 cannot be null" indicates that the intelliair.address.Address1 field must be defined not null.

And, I don't think that you pre defined value for @MyAddress before passing it to the stored procedure.
Unless defined it is treated as NULL and hence is the error thrown.

To cross check values before calling the stored procedure like :

select @MyAddress;  -- ,@myFarm, @MyName, @MyCity, @MyState, @MyZip, @MyCountry;

Update 1:

You can call stored procedure by directly inputting values for each of the parameters.
Example:

call new_user_create(  
    'my Farm value', -- @myFarm  
    'E B', -- @MyName  
    'My Address is SO', -- @MyAddress1  
    'My City is Coders', -- @MyCity  
    'CA', -- @MyState  
    '12345', -- @MyZip  
    'US' -- @MyCountry
);
like image 152
Ravinder Reddy Avatar answered Sep 24 '22 15:09

Ravinder Reddy