我有一种新的脚本在sql中,我遇到了我的一个脚本中的错误。
有问题的部分是:
有问题的部分是:
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE dbo.WorkspaceSettings ( Id INT NOT NULL IDENTITY PRIMARY KEY,ReportColorRGB1 VARCHAR(15) NOT NULL DEFAULT '61,105,138',ReportColorRGB2 VARCHAR(15) NOT NULL DEFAULT '180,210,121' ) GO ALTER TABLE Workspace ADD WorkspaceSettingsId int NOT NULL default 1; GO ALTER TABLE Workspace ADD CONSTRAINT FK_WorkspaceSettings_Workspace FOREIGN KEY (WorkspaceSettingsId) REFERENCES WorkspaceSettings(Id); GO
并收到以下错误消息:
Msg 547,Level 16,State 0,Line 1
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint “FK_WorkspaceSettings_Workspace”. The conflict occurred in database “ClearRisk2_0”,table “dbo.WorkspaceSettings”,column ‘Id’.
有人可以告诉我哪里错了吗?
解决方法
您为Workspace.WorkspaceSettingsId列指定的默认值1不存在于WorkspaceSettings表中,因此FK违例。