简体   繁体   中英

Stored procedure to insert multiple rows into at least 2 tables

I have looked but not sure if it is possible.

I have a database of rates. A service has multiple tables involved and they are:

  • option record - one for the service in OPT table
  • validity record - one for each date range is valid, from and to, in OSR table
  • actual rate - has a minimum of 12 records per OSR (date range), in OPD table

I have created an Excel report to calculate the required rates that need to e input into the system and this was uploaded to SQL and I have Insert statements to create the OSR records and OPD records and when run as standard query works a treat and is correct.

For other staff that are even less familiar with SQL I would like to find the best way for them to run the process to upload the rates with out having to run multiple queries.

I have NO idea about stored procedures so I was wondering if it is possible to have a stored procedure to be able to run the insert function? If it is could it be one stored procedure, or would I need 2 for each table? The OPT doesn't need to be created as this already exists, it is the date range and rates that I am looking at inserting.

I know I have not provided any specific scripts at this stage I would like just advise if it can be done first.

SPs are typically capable of batching multiple SQL statements - including INSERT s - so it is likely that you would only require one. Having not specified the RDBMS you're using, it is difficult to give an authoritative answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM