I am going over my database and I wanted to know how many primary keys are missing from my tables. Now sometime I have only one primary key which is integer, which is easy, I looked at this SQL: find missing IDs in a table but it was for numeric column.
I got the below solution from SO itself and it helps in case the PK was integer. selecting only the PK into a file I awk through it to find the next missing sequence
gawk '$1!=p+1{print p+1}{p=$1}'
Now My question revolves around the varchar Primary keys. like a Order reference number perhaps which is not a sequentially increasing integer but a string/varchar/alphanumeric column has anybody tried this already. (a value like A123Z43), in integer/numeric it was easy, I add 1 and I get the next sequence.
I am not sure but it just struck me, would the hash of one key and the next have anything to do with it. I will see if I can try that.
this will get more complex if i got two columns as Primary Keys one being numeric and the other being varchar.
I am working with SQL server and Postgres at the moment.