[Gloucs] mysql insert query

Glyn Davies glynd at walmore.com
Sun Nov 6 22:23:43 UTC 2011


'lo

I have a noddy mysql query which I'm sure someone can help me with. Am
a complete novice with mysql and SQL in general.

Assume you have two tables. Hopefully I have described this okay.

Authors
id - auto_num, primary key
Name - Author's name

and

Books
id - auto_num, primary key
Title - Book title
Author - Author.id, foreign key

Say you want to insert a book into the db.

Add the Author, get the id for that Author's entry, then add the book
with the Author value being that previosly learnt.

First insert is easy as is getting the id.

But I'm failing to insert into the Books table due to foreign key
restraints. Can I insert? Should it be an update?

Can provide more detailed info if required but I think my problem is a
numpty one a pro could answer with ease.

P.S. Database was designed and built in MySQL Workbench so good chance
I've made a mess of that!

-- 
Best Regards
Glyn Davies



More information about the gloucs mailing list