I have two tables
books table
- ID (PK)
- Title
- Author
- Genre
- ISBN
- Price
- publisher
- Year
bookAwards table
- ID (FK) -- referencing Books.ID
- Awardname
- Year
ID of bookAwards is foreign key of ID in books table.
How can I insert into books table at the same time into bookAwards table?
When I am trying to insert into books table it gives the error that foreign key causes?
I want to insert into books table the values and then an awardname with a year into bookAwards?
Any help will be much appreciated.
You can use
STORED PROCEDURE
on this so you will only call once from the application level. Example,And on the application level or on any sources that you want to call this procedure,
For security purposes, you can still parameterized the procedure, eg