Forums

This topic is locked

Insert Record with the same autogenerated ID

Posted 07 Apr 2007 23:03:24
1
has voted
07 Apr 2007 23:03:24 Subha Sasidharan posted:
Hi,

I need help with inserting records into SQL Tables with the same Autogenerated ID from the first page.
I have 5 web pages which inserts records into 5 tables,but the ID from the first page should be maintained for all the pages.

This is how the page flows, once the first form is submitted , the action goes to another page where the insert is performed and redirects the url to the second page.

I am not using the MX Insert from the server behavior.

Can someone help me to get this to work.

Thanks,
Subha.

Replies

Replied 09 Apr 2007 21:12:10
09 Apr 2007 21:12:10 Alan C replied:
turn off auto increment on the second (and other tables) then you can designate a column as the key and insert the key from the first table -

Why are you dividing the table up into 5 parts like that? it could be better to have one large table so that you do not need joins later
Replied 10 Apr 2007 18:32:32
10 Apr 2007 18:32:32 Subha Sasidharan replied:

Thank you!.It was done that way as the same user can have multiple records.

at this note,what would be the best way to insert another record for the same user?
Replied 11 Apr 2007 17:07:45
11 Apr 2007 17:07:45 Alan C replied:
Foreign key

Your user has a unique identifier - like their autogenerated ID from the first page, that goes into other tables as a foreign key.

I have something like that in my properties site, the property manager has a record with ID, name, nickname etc, then each property manager can have many properties that they manage.

Each property record has the unique id of the manager in it as a foreign key, so the query to show a manager all their properties selects all the records that have the id field = manager unique id, then sorts by property name ASC.

The result in displayed as a list and each property made a link so that the manager can click the property name and then see the details for that property.

Hope that helps

Reply to this topic