Home > database >  PB to enter a data, and to save the data into two tables
PB to enter a data, and to save the data into two tables

Time:10-26

Existing a warehousing information: id 1, the name of washing powder, foshan city, the add, the price of 3.5, num is 200, 001, sun date 2014-08-27
To save the data at the same time to A, B in the table, if no. 1 of the database data, num data to increase the corresponding number; Without this data, the new data which,
A table id name add price num sun date
B table id name num

CodePudding user response:

refer to the original poster qq_29403979 response:
an existing library information: id 1, the name of washing powder, foshan city, the add, the price of 3.5, num is 200, 001, sun date 2014-08-27
To save the data at the same time to A, B in the table, if no. 1 of the database data, num data to increase the corresponding number; Without this data, the new data which,
A table id name add price num sun date
B: table id name num


With A select count (*) from A where Anderson, d=: id; According to the judgment whether there is data, if there is no use insert, if you have it with the update

CodePudding user response:

The code I wrote the following
Int kk
Select count (*)
Into: kk
The from ruku
Where id=: is_id;
If kk & gt; 0 then
The update ruku
The set of num=num + : is_num
Where id=: is_id;
The else
Insert into "ruku
"(" id ", "name", "add", "price", "date", "num" and "sun")
Values (is_id, : is_name, : is_add, : is_price, : is_date, : is_num, : is_sun);
End the if
This can only be added to a table, how to add to the second table for help

CodePudding user response:

reference 1st floor lzp_lrp response:
Quote: refer to the original poster qq_29403979 response:

Existing a warehousing information: id 1, the name of washing powder, foshan city, the add, the price of 3.5, num is 200, 001, sun date 2014-08-27
To save the data at the same time to A, B in the table, if no. 1 of the database data, num data to increase the corresponding number; Without this data, the new data which,
A table id name add price num sun date
B: table id name num


With A select count (*) from A where Anderson, d=: id; According to the judgment whether there is data, if there is no use insert, if you have it with the update can


The code I wrote the following
Int kk
Select count (*)
Into: kk
The from ruku
Where id=: is_id;
If kk & gt; 0 then
The update ruku
The set of num=num + : is_num
Where id=: is_id;
The else
Insert into "ruku
"(" id ", "name", "add", "price", "date", "num" and "sun")
Values (is_id, : is_name, : is_add, : is_price, : is_date, : is_num, : is_sun);
End the if
This can only be added to a table, how to add to the second table for help

CodePudding user response:

Insert into "ruku
"(" id ", "name", "add", "price", "date", "num" and "sun")
Values (is_id, : is_name, : is_add, : is_price, : is_date, : is_num, : is_sun);

And then write an insert is inserted into the second table

Insert into B (id, name, num) values (: is_id, : is_name, : is_num);
  • Related