Query on uniqueidentifier / Null values

Benjamin Jackson 21 Reputation points
2022-08-20T00:15:58.68+00:00

I setup a table with an auto-generated ID field quite a while ago, but have forgotten how I did it. I've tried replicating the ID column into a different table I've just created, but all I'm getting is null results.

Can anyone help from the provided screenshots below? What (probably very basic function) am I doing wrong?

SQL Query to populate table WITH ID generated
233061-image.png

SELECT result from table WITH ID generated:
233007-image.png

SQL Query to populate table WITHOUT ID generated
233034-image.png

SELECT result from table WITHOUT ID generated:
233051-image.png

Properties for both ID fields
232929-image.png

Developer technologies Transact-SQL
SQL Server Other
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2022-08-20T04:19:32.46+00:00

    Try opening the Design of BREquipmentList table. Select the ID column, go to "Default Value or Binding" property, and enter newid().

    You can also execute a statement like this:

    ALTER TABLE [dbo].[BREquipmentList] ADD CONSTRAINT [DF_BREquipmentList_ID] DEFAULT (newid()) FOR [ID]


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.