How do you generate a primary key on an RDBMS (Sql Server or MySql) other than using an "autoincrement field".
I'm trying to write code so that it will function using either .DBF's or with an RDBMS backend... however, it seems they have complete opposite "best ways" of generating PK's.
(I know VFP8 (or is it the up-and-coming 9?) has auto-inc fields built in, but I don't have it...)
in VFP DBF's a good way is to keep a table just for tracking the next ID, and do this to get an ID:
[ol][li]Lock that NextID table,
[li]increment the record for the DataTable having a record added,
[li]Unlock that NextID table
[li]Insert the new record, with the good PK value, into the dataTable[/ol]
However, with an RDBMS, it goes something like:
[ol][li]Insert the new record into the DataTable
[li]Query the DataTable for that new record
[li]One field on that query is the auto-filled PK (is there a way, other than with Stored Procedures, to get the new PK value back at the same time as inserting the record?)[/ol]
Essentially, the problem is: When do you get the PK value, and where do you pass it as a parameter? (to be compatible, code-structure-wise, with either)
I'm trying to write code so that it will function using either .DBF's or with an RDBMS backend... however, it seems they have complete opposite "best ways" of generating PK's.
(I know VFP8 (or is it the up-and-coming 9?) has auto-inc fields built in, but I don't have it...)
in VFP DBF's a good way is to keep a table just for tracking the next ID, and do this to get an ID:
[ol][li]Lock that NextID table,
[li]increment the record for the DataTable having a record added,
[li]Unlock that NextID table
[li]Insert the new record, with the good PK value, into the dataTable[/ol]
However, with an RDBMS, it goes something like:
[ol][li]Insert the new record into the DataTable
[li]Query the DataTable for that new record
[li]One field on that query is the auto-filled PK (is there a way, other than with Stored Procedures, to get the new PK value back at the same time as inserting the record?)[/ol]
Essentially, the problem is: When do you get the PK value, and where do you pass it as a parameter? (to be compatible, code-structure-wise, with either)