Query on uniqueidentifier / Null values

Benjamin Jackson 21 Reputation points

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

SELECT result from table WITH ID generated:

SQL Query to populate table WITHOUT ID generated

SELECT result from table WITHOUT ID generated:

Properties for both ID fields

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

Accepted answer
  1. Viorel 112.1K Reputation points

    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