如何引用 UNIQUEIDENTIFIER DEFAULT NEWID() 列
How to reference a UNIQUEIDENTIFIER DEFAULT NEWID() Column
我正在尝试引用 uniqueidentifier default newid() 列,但它在第 11 行中给我一个错误:引用的 table.
没有主键或候选键
CREATE TABLE tblPhoneTypes (
PhoneTypeID UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID(),
PhoneTypeDescription VARCHAR (50) NOT NULL,
PhoneTypeIsActive BIT NOT NULL,
UpdateDate DATETIME)
CREATE TABLE tblPhones(
PhoneID UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID(),
PhoneNumber INT NOT NULL,
PhoneTypeIDFK UNIQUEIDENTIFIER NOT NULL FOREIGN KEY REFERENCES
**tblPhoneTypes**(PhoneTypeID), //ErrorLine
PhoneIsActive BIT NOT NULL,
UpdateDate DATETIME NOT NULL )
只需添加主键约束:
CREATE TABLE tblPhoneTypes (
PhoneTypeID UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID(),
PhoneTypeDescription VARCHAR (50) NOT NULL,
PhoneTypeIsActive BIT NOT NULL,
UpdateDate DATETIME)
第二个 table :
CREATE TABLE tblPhones(
PhoneID UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID(),
PhoneNumber INT NOT NULL,
PhoneTypeID UNIQUEIDENTIFIER FOREIGN KEY REFERENCES tblPhoneTypes(PhoneTypeID),
PhoneIsActive BIT NOT NULL,
UpdateDate DATETIME NOT NULL )
我正在尝试引用 uniqueidentifier default newid() 列,但它在第 11 行中给我一个错误:引用的 table.
没有主键或候选键CREATE TABLE tblPhoneTypes (
PhoneTypeID UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID(),
PhoneTypeDescription VARCHAR (50) NOT NULL,
PhoneTypeIsActive BIT NOT NULL,
UpdateDate DATETIME)
CREATE TABLE tblPhones(
PhoneID UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID(),
PhoneNumber INT NOT NULL,
PhoneTypeIDFK UNIQUEIDENTIFIER NOT NULL FOREIGN KEY REFERENCES
**tblPhoneTypes**(PhoneTypeID), //ErrorLine
PhoneIsActive BIT NOT NULL,
UpdateDate DATETIME NOT NULL )
只需添加主键约束:
CREATE TABLE tblPhoneTypes (
PhoneTypeID UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID(),
PhoneTypeDescription VARCHAR (50) NOT NULL,
PhoneTypeIsActive BIT NOT NULL,
UpdateDate DATETIME)
第二个 table :
CREATE TABLE tblPhones(
PhoneID UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID(),
PhoneNumber INT NOT NULL,
PhoneTypeID UNIQUEIDENTIFIER FOREIGN KEY REFERENCES tblPhoneTypes(PhoneTypeID),
PhoneIsActive BIT NOT NULL,
UpdateDate DATETIME NOT NULL )