Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create table with UNIQUEIDENTIFIER as PK

Tags:

sql

t-sql

I have been trying (unsuccessfully) to create a table with a UNIQUEIDENTIFIER as the primary key. The script below will create the table just fine, however there is no PK specified. This is my first time using a UNIQUEIDENTIFIER, however. Any ideas?

T-SQL

CREATE TABLE [dbo].[AgentRelationshipCodes]
(
Id UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID(),
RelationshipId char(3) NULL,
EffectiveDate datetime NULL,
LastChangeDate datetime NOT NULL,
LastChangeId char(6) NOT NULL,
AgtTableId int FOREIGN KEY REFERENCES AgentTransmission(ID)
);

Management Studio

enter image description here

like image 715
NealR Avatar asked Sep 07 '25 17:09

NealR


1 Answers

create table [dbo].[AgentRelationshipCodes]
(
    Id UNIQUEIDENTIFIER NOT NULL PRIMARY KEY DEFAULT NEWID(),
    .
    .
    .
)

Repeat for the other tables.

  • Answered here by Christian Hayter
like image 72
Mark C. Avatar answered Sep 10 '25 06:09

Mark C.