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

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,367 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,601 questions
{count} votes

Accepted answer
  1. Viorel 114.7K 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