Skip to main content
Question

How to generate GUID in FSM?

  • July 4, 2024
  • 3 replies
  • 65 views

Lukasz
Do Gooder (Customer)
Forum|alt.badge.img+2

Hi,

We need a solution to generate GUID in FSM. It cannot be a counter,  it cannot be only numeric, it needs to be asymmetric and random. The result of NEWID() sql function is exactly what we need.

Currently, in our test environment, we have set up a trigger on the table to create it after-insert into one of user_defX fields.

Is there any other way?

3 replies

AdrianEgley
Hero (Customer)
Forum|alt.badge.img+14
  • Hero (Customer)
  • July 4, 2024

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([dbo].[task].task_id AS VARBINARY(8)), 2), 5, 0, '-')) AS guid

 

Hope this helps.

Ady


Lukasz
Do Gooder (Customer)
Forum|alt.badge.img+2
  • Author
  • Do Gooder (Customer)
  • July 4, 2024

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


Shneor Cheshin
Superhero (Employee)
Forum|alt.badge.img+28
  • Superhero (Employee)
  • July 4, 2024

@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!