I have a table that contains two columns
ID | Name
----------------
1 | John
2 | Sam
3 | Peter
6 | Mike
It has missed IDs. In this case these are 4 and 5.
How do I find and insert them together with random names into this table?
Update: cursors and temp tables are not allowed. The random name should be ‘Name_’+ some random number. Maybe it would be the specified value like ‘Abby’. So it doesn’t matter.
Using a recursive CTE you can determine the missing IDs as follows
The option
MAXRECURSION 0will allow the code to avoid the recursion limit of SQL SERVERFrom Query Hints and WITH common_table_expression (Transact-SQL)
Generating the RANDOM names will largly be affected by the requirements of such a name, and the column type of such a name. What exactly does this random name entail?