They would much rather prefer that the database assign the key by auto incremented numbers controlled by the database, not be worried about it and be done with it. Another column is introduced using identityĪs the primary key, because most don't want to go through a Frankenstein primary key dance. Now I do use autonumbers as a key in transaction files, but never as a foreign key. Why introduce another column when it's not necessary. Now I am sure there are situations where using autonumbers as keys/foreign keys is necessary because there is no other option and it can be done easily as you indicate, but when there are other options, it's a poor practice in my opinion.
#Xojo record windows
Most of the conversions have been from databases on one platform to another platform (System/3 to System/34 System/34 to AS/400 AS/400 to Oracleįor windows and AS/400 to SQL Server) so this issue didn't apply and the databases on all platforms were designed by me so not really a challenge. And I have converted Oracle to SQL Server several times where the issue did apply and while doable, it's I have done a number of data conversions over the past 45 years and am doing one now. Now I do useĪutonumbers as a key in transaction files, but never as a foreign key. Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar didn't say there were issues with using autonumber keys and foreign keys, I just think it's a poor practice and still do when other options are available. That's my opinion.
#Xojo record professional
Under the covers what is responsibleĪre triggers and has been done for decades while those who attempt to work around this in general is like representing yourself in court w/o a professional lawyer. Generally speaking (this has already been mentioned) that a connection takes care of the increment operation and is thread safe.
You should look at many tiered database designs that function on an enterprise level for perspective. The difference between genius and stupidity is that genius has its limits. Seen duplicate GUIDs generated with large number of rows (> 1,000,000).
My data tier will work with any database, but I only recommend SQL Server and Oracle. My clients pick the database, I just provide the application. Moving a SQL Server database to an Oracle database (or vice-versa) is a chore when a autonumber is used to join tables. I use autonumbersĪs keys, but never use the identity column to join tables. I think using an autonumber (identity) for a key that will be used to join to another table is a poor practice. Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Console.WriteLine("ID: ", dt.LastValue(Of Int32)("Identifier"), dt.LastValue(Of String)("FirstName"))Ĭreate LanguageExtensions.vb and place the following into it Module LanguageExtensions _ _ Public Function LastValue(Of T)(ByVal dt As DataTable, ByVal ColumnName As String) As T Return dt.Rows.Item(dt.Rows.Count - 1).Field(Of T)(dt.Columns(ColumnName)) End FunctionEnd Module I used a extension as I keep this in a team library and is easy to figure out what it does.
#Xojo record code
If from a DataTable you can use the code below which is enclosed in a Language Extension which can be used as a regular function also. If you are hard set on this the best idea would be to select that column and sort DESC, get the value for the first row using OleDb ExecuteScalar and cast the result to the proper data type.