From my experience, I learned that using the surrogate INT data type column as the esp primary key. the IDENTITY key column provides better performance than using a GUID or char / varchar data column as the primary key. I try to use the IDENTITY key as the primary key, where possible. But recently, I came across a scheme in which tables were split horizontally and controlled through a split view. Thus, the tables could not have an IDENTITY column, as this would make the Partitioned View not updatable. One of them was to create a keygenerator mannequin table with an identifier column to generate identifiers for the primary key. But that would mean having a "keygenerator" table for each of the Partitioned View. My next thought was to use float as my primary key. The reason is the following key algorithm that I developed
DECLARE @KEY FLOAT SET @KEY = CONVERT(FLOAT,GETDATE())/100000.0 SET @KEY = @EMP_ID + @KEY Heres how it works. CONVERT(FLOAT,GETDATE())
gives a float representation of the current datetime, since internally all datetimes are represented by SQL as a float value.
CONVERT(FLOAT,GETDATE())/100000.0
converts the float representation to a full decimal value, that is, all digits are shifted to the right of ".".
@KEY = @EMP_ID + @KEY
adds the identifier of the employee, which is an integer with this decimal value.
The logic is that the employee identifier is guaranteed to be unique for all sessions, since the employee cannot simultaneously connect to the application several times. And for the same employee, every time a key is generated, the current time and date will be unique.
In a unique way in all sessions of employees and in time.
So, for Emp Ids 11 and 12, I have key values like 12.40046693321566357, 11.40046693542361111
But my concern is whether the floating point data type offers the primary key advantages over choosing GUIDs or char / varchar as primary keys. It is also important that splitting the float column will be part of the composite key.