can anyone tell how to use stored procedure in mysql database to insert and update same table? -


can tell how use stored procedure in mysql database insert , update same table?

 create procedure inst_upd_pro(in product varchar(50),price int(30),stock   int(30),active int (30))  begin   declare id int;   select id_pro id products;   if(id_pro=id)then   update products set product=product, price=price, stock=stock,    active=active   id_pro=id;   else   insert products (product, price, stock, active) values   (product, price, stock, active);   end if; 

for clarity , avoid confusion (for , mysql) name incoming parameters prefix of in_ , declared variables dec. select incorrect - should looking specific product (that in in parameter) , if condition incorrect should comparing declared variable in parameter.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -