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!

Insert into two tables joined by Autoincremented ID

Status
Not open for further replies.

JontyMC

Programmer
Nov 26, 2001
1,276
GB
I am creating code for a forum. I have a table of topic titles with columns TopicID, TopicTitle and Author. The TopicID is auto-increment. For the author to start a topic, they have to submit a post and topic title. I have another table of posts with TopicID, Post and Author. How can I create a statement that inserts a new topic title into topic titles table and inserts the post into post with the same TopicID as the one created by the auto-increment?

Jon

"Asteroids do not concern me, Admiral. I want that ship, not excuses.
 
you really should post it in the database forum.

Traditionally you can always use Sequences as a ID generator. This is now also part of ANSI SQL.

With DB2 generated columns in Version 8 on Unix/Windows there is a new SQL construct
Select .. from update/insert which can return the generated ID to be used in other statements. This is NO ansi SQL, but additional sequences can be avoided then.


Juliane
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top