Editing the ID of SpQuery table records

7.11.3
I accidentally deleted a query that has been linked to as a QR code in some printed material we made a few months ago. I have the xml for the query itself, but reuploading the query as a new record means a new id in the SpQuery table, and in turn that means the URL is not the same as it previously was.

Is there any way to force the system to assign a specific number to theSpQueryID? My guess based on this thread is no and that I’m out of luck. But wanted to check nonetheless. Thanks!

Hi @nfshoobs,

You would need to update this on the backend, as primary key IDs for records are manually assigned and not editable. You could edit the SpQueryID value in the database using SQL, and as long as you assign a value that is not currently in use, the URL should then work as you expect.

Thanks! I don’t normally think about what’s possible with SQL editing since whenever I make changes that way the changes actually get made by our IT folks.
I am glad to hear its possible to just directly edit the id field like this!

For future reference, this was not actually possible by just manually editing the SpQueryID, because other tables (such as ModifiedByAgent, CreatedByAgent, SpUser, etc) have the SpQueryIDas a foreign key.

What we did instead was to use DBeaver’s ‘duplicate row’ function to copy the query we wanted to change the SpQueryID of, and then manually changed the SpQueryID of the duplicated row before saving it. That worked.

The end result was a new query with the desired content and the desired ID, leaving the old query unchanged, and I manually deleted the old query after confirming the new one worked.

1 Like