question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Output of generated keys not working for UUID / uniqueidentifier

See original GitHub issue

I am using UUID / uniqueidentifier primary keys.

CREATE TABLE test (
  id UNIQUEIDENTIFIER DEFAULT NEWID(),
  text VARCHAR(255)
)

When inserting a new object, I dont get the generated id. GENERATED_KEYS is empty.

INSERT INTO test (text) VALUES('test') select SCOPE_IDENTITY() AS GENERATED_KEYS;

Will return NULL.

That is an issue of SQL Server but the workaround would be to use the OUTPUT syntax:

INSERT INTO test (text) OUTPUT inserted.id VALUES('test');

That will actually return something like | id | B5BA707B-872E-4BFC-8A96-97A1D789E74C |

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
essentinalcommented, Oct 27, 2020

Whatever works with custom statements, r2dbc-mssql doesn’t return ids with spring-data-r2dbc where other drivers do.

We switched to r2dbc-postgresql for that reason and everything works fine.

0reactions
mp911decommented, Oct 27, 2020

Thanks, I missed that subtlety.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem obtaining entities with uniqueidentifier primary key
I had the same problem and I solved it by adding uuid-char type to column.
Read more >
Auto generated SQL Server keys with the uniqueidentifier or ...
Another way to auto-generate key values is to specify your column as a type of uniqueidentifier and DEFAULT using NEWID() or NEWSEQUENTIALID().
Read more >
UUID or GUID as Primary Keys? Be Careful! | by Tom Harrison
Databases support integer primary keys and they are fast and elegant. ... Another problem is fragmentation — because UUIDs are random, ...
Read more >
The best UUID type for a database Primary Key - Vlad Mihalcea
In this article, we are going to see what UUID (Universally Unique Identifier) type works best for a database column that has a...
Read more >
Understanding the GUID data type in SQL Server
Let's see what issues we face if we have redundant records within ... is also the primary key column for the newly created...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found