Use LAST_INSERT_ID() to get the id. LAST_INSERT_ID() is connection-specific, so you will get the correct value regardless of other users.

See <http://www.mysql.com/doc/en/example-AUTO_INCREMENT.html> for more.

Michael

David Johnston wrote:
I have a database with two tables (well more but only two are important here)

When a risk is created it can have one or more plans (hence the second table) The data that is inserted comes from a cgi form. So I want to insert all risk data into risk_tb and plan_tb.

The question is how do I do this with linked tables? Some people have suggested using last_id(); to get the last inserted id, but this is a multi-user database, so if another user inserts a record, wont this value be the wrong one?

risk_tbl which contains
+---------------------------------------------+
project_id         int
risk_id             int auto-increment
some other fields

Primary Key (project_id, risk_id)
+---------------------------------------------+

plan_tbl
+-------------------------------------------------------------------+
plan_id            int auto_increment
project_id        int (should be the project id for the risk)
risk_id            int (should be the risk_id)
plan

primary key (plan_id)
+-------------------------------------------------------------------+









--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to