I make a simple cms.
Each post has subject, content, and several image, and use 2 table
each time create new post, have to insert table a subject and content, then insert table b image, but if insert table b fail, have to delete last insert table a.
problem both happen when update and delete.
table a
article
id subject content
1
table b
article_image
id article_id file_path file_sequence
1 1 dkeorkw.jpg 2
1 1 dklwekw.jpg 1
I'm wondering should i combine 2 table, any suggestion? most people how to do
most people how to do
You shouldn't combine the two tables as you'll have issues later on. Most people do normalized. See database normalization.
Most database systems come with mechanisms that allow you to transact both statements and rollback if one of them fails. You can read more about how MySQL handle's this in their documentation:
START TRANSACTION; INSERT ...; INSERT ...; COMMIT;