Hello
I'm trying to make an insert statement, that inserts into a table with foreign keys, and if a foreign from another table doesn't exists it creates it and inserts the new ID. It's hard to explain I hope you understand what I mean.
I've seen this piece of SQL somewhere but i can't seem to find it or write it myself, can anyone please help?
Any help will be appreciated.
Sincerely,
Daniel
INSERT statement with FK INSERT if not exist
Page 1 of 13 Replies - 1069 Views - Last Post: 15 May 2012 - 05:45 AM
Replies To: INSERT statement with FK INSERT if not exist
#2
Re: INSERT statement with FK INSERT if not exist
Posted 14 May 2012 - 07:16 AM
It's nothing more than a multi-part sql procedure using a boolean variable and if statement. Create boolean variable.. have it be set true or false if a select statement querying the foreign key table contains the pertinent data. If it does not exist then do an insert... else just exit the procedure or do what ever you want to do if it exists.
#3
Re: INSERT statement with FK INSERT if not exist
Posted 15 May 2012 - 02:02 AM
I'm still a bit new to SQL, could you please give an example of what you mean?
#4
Re: INSERT statement with FK INSERT if not exist
Posted 15 May 2012 - 05:45 AM
Alternatively you could read up on the syntax and usage... select statements, user variables, and if-syntax!
https://dev.mysql.co.../en/select.html
https://dev.mysql.co...-variables.html
https://dev.mysql.co...-statement.html
https://dev.mysql.co.../en/select.html
https://dev.mysql.co...-variables.html
https://dev.mysql.co...-statement.html
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote






|