Hi @Lukasz ,
We do this for one of our processes by creating a view.
This is how we create the column as part of that view.
CONVERT(uniqueidentifier, '76214778-6EK2-4L75-' + STUFF(CONVERT(VARCHAR(36), CAST(Tdbo].]task].task_id AS VARBINARY(8)), 2), 5, 0, '-')) AS guid
Hope this helps.
Ady
Hi @AdrianEgley ,
Many thanks for your answer.
Our GUID must be random and with as high entropy as possible as it’s used for secure access purposes. I see you’re performing some conversion of the task_id and also locking a big part of your ID which is reducing entropy and uniqueness. As it’s working perfectly for you, unfortunately it wouldn’t work for us. We just use basic SQL:
update task
set user_defx = NEWID()
I was hoping there may be some FSM solution so one does not need to resort to SQL shortcuts.
Many Thanks,
Lukasz
@Lukasz
You found the best way to generate a unique ID without a customisation.
If you want to add complexity you can concatenate something like a timestamp.
select concat(NEWID(), '-' , DATEDIFF(SECOND, '1970-01-01', GETUTCDATE()))
Cheers!