When I insert a new record into a table then is it possible to know the newly generated primary key for this record if the primary key is auto increment.Is there any efficient way to know he same while firing insert query.
You can fire an select query to find out. MySQL you can do "SELECT LAST_INSERT_ID()" to get the last inserted (in auto generated column) by that specific connection. This is connection specific (other insertions from different connections won't affect the result). Which DB are you using?
That's why I quote in my second reply, though the chances are rare, but there may be the case when multiple user inserting into same table. One way we can avoid this by using, Store Procedure or function which takes the insert values as parameter and return an auto incremented id,
Please check out the syntax for SP, its not correct.