Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is lock tables needed ?

Status
Not open for further replies.

spookie

Programmer
May 30, 2001
655
IN
Hi,
I am issuing two insert commands in two different tables.
The last increment id (auto generated) of the first table shd go into the second table.
so i am using mysql_insert_id() on the first table and inserting that in second.
since the table types are MyISAM and InnoDB is not enabled,
i cant use transaction.
i just wonder do i need to lock the tables in order to ensure both the statment shd be one transaction..?

Any suggestions are welcome as always




--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
When you use mysql_insert_id(), you don't need the two queries in the same transaction. That's why that function exists.

MySQL maintains the last autoincrement id on a per-connection basis. Your first insert and subsequent fetch of the id will return only the id you set.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Thanks sleipnir214

That cleared my doubt i had for a long time.

But what if the MySQL completes the first query ie inserting record in table 1 and it crashes after it?

How can i handle the situation best ?




--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Yes,
What i mean is knowing the limitation that u cant use transactions because the table type does not support it and u cant change the table type, how could i handle the situation best.
But i think, u cant help it when power goes or server crushes after the first query in this situation.
pls correct me if i am wrong.






--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top