Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Adding a row to a table and delay setting PK
Message
De
10/03/2018 05:10:47
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
01658640
Message ID:
01658659
Vues:
46
>>>A table in SQL Server has a PK column, Identity. I would like to be able to add a row/record to the table without actually setting the value in the PK column, until the VFP 9 application saves the row/record. I think the only way to do it is to be able to "get" the next PK value (Identity) without actually adding a row. Then, then user Saves the record, add new row. But then (as I type it, I realize) the PK column will get a new Identity value.
>>>
>>>Is something like I am describing above possible?
>>
>>A primary key with Identity definition will auto generate the value by itself. As soon as you insert a new row, that field is populated automatically by SQL Server. That is the best approach to use. There used to be a time when we had to use our own routines to generate such key. I haven't heard of that being done manually since years now.
>
>Thank you.

If you go this way - which is solid - standardize on using CA throughout the project and abstract getting PK after row save and inserting into FK fields of linked tables after each row insert in the hook methods of a common CA class.
Personally I think the overhead of calling a method of the CA responsible for the alias having the FK minimal enough for the clarity it brings to code using mostly CA (and then "(CA.alias)") instead of passing alias() to other functions. YMMV ;-)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform