5

uniq

I tried a lot by Field Calculator but it gives me NULL as you show in table and another try it gives me value 1 in all rows.

Most of examples, on internet they are explaining old version and I have QGIS 3 and I am not sure how can I add id for all rows .

If I want to generate random id, how can I do it also.

I did as suggested in answer $id

enter image description here

But could i ask why the values are not looks like counter, it looks random. If i need to increase by one, how can i do that?

Taras
  • 32,823
  • 4
  • 66
  • 137
potter90
  • 111
  • 2
  • 10

2 Answers2

7

The easiest and preferred way is to use the processing algorithm "Add Autoincremental Field"

spatialthoughts
  • 6,106
  • 28
  • 49
3

The simplest answer is the $id variable.

Be careful though, it doesn't auto-increment after your first field calculation.

gisnside
  • 7,818
  • 2
  • 29
  • 73