Primary Key Value?


Author
Message
Ben Hayat
Ben Hayat
Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
All my years of database programming, I had worked directly with RDBMS. This new switch over to .Net and dealing with ROM seems to require new strategy in some areas.



I had always maintained the primary key value, using an Integer field and maintained the incremental myself regardless which database engine I was using. This way I could switch DB and things would be the same.



My question is, to have unique Primary keys, can I still use the same techniques as I have before or are there other approaches that would be better when working in Object Relational Mapping environment? Perhaps I've missed it in docs, is there a pattern in SF that I should follow to maintain a safe position, especially when linking to other tables?



Thank you in advance!


..ßen
Replies
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Greg is right... if you want to assign your own primary keys, you can Set the PrimaryKeyIsAutoIncremented to False and specify the PK value within the SetDefaultValues event handler.

However, I would just let the DB assign the PKs.  Our medical software used to assign it's own PKs.  We had a database table that stored the next PK value for each of the tables in the database.  However, we did this because the system was designed in the old days of VFP when there was no auto increment option for the PK.  We wish we never had to do it.  Maintaining that file was the biggest pain the the rear ever.

Nowdays, you can't find a database in it's current version that doesn't support auto incrementing PKs.  It's much easier to just let the database handle it.

Ben Hayat
Ben Hayat
Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
Thanks Greg & Ben;



However, we did this because the system was designed in the old days of VFP when there was no auto increment option for the PK. We wish we never had to do it. Maintaining that file was the biggest pain the the rear ever.




I agree with you 100%! I had it the same way too where I had another filer that each record had two fields (FileName, Last_ID). And somtimes in heavy multi user, due to serveral people hitting the "increament file" at the same time, I would see my "Next_ID" would skip or worst, two records get the same number.



And that's why I post these questions to avoid the old pitfalls.

Thanks!

..ßen
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search