I want to run an automation for adding random value into data extension field.

I have data extension with name RecordsDe which having 3 field FieldA, FieldB & PKey.

Now i want to add random number value to PKey that will be unique for each row.

Any solution for this?


1 Answer 1


The naming of your fields suggests that PKey should be your primary key, which cannot be empty in the first place, if you set up the data extension correctly.

So therefore you need to either

  • add this functionality to the query that initially fills your data extension, or
  • set it as a default value in the data extension setup.

For the SQL solution you could use the NEWID-function:

  NEWID() as PKey,

The data extension setup-version would be adding GUID() as default value for that field.

However, both solutions lead to IDs that aren't numerical, but rather IDs in GUID format (alphanumeric with dashes as separators).

Related documentation:

  • Thanks Markus Slabina, Actually i am updating RecordsDe from the other data extension using automation that required Primary key in target Data extension(RecordsDe). So i have added Pkey in as primary key in target data extension. So i want to add random value to it to make sure it will not be empty. Commented Aug 6, 2019 at 13:39
  • 1
    In that case the NEWID-solution should work for you. I added a code snippet for your reference. If my answer helped, please mark it as accepted, so others can easily see this has been resolved. Commented Aug 6, 2019 at 15:15
  • Hi Markus, the code snippet you share worked like magic +100 Likes for that. I am new to MC if you share any reference guide for SQl Code that used for the most of the task in MC will help me in learning and other tasks. Thanks once again! Commented Aug 7, 2019 at 7:49
  • I already had SQL experience when I started with Marketing Cloud and I don't know of any specific resource for Marketing Cloud, but that isn't necessary in my opinion. Just search for SQL tutorials, as there are a lot of good ones out there (for the trickier functions Microsoft SQL ones, as this is used by Marketing Cloud). Commented Aug 7, 2019 at 7:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .