首页 > 解决方案 > 创建两个共享依赖关系的表

问题描述

我试图在 sql 中创建两个共享键的表,但我收到一条错误消息:在这种情况下,无法创建、删除、启用或禁用多个名为“PK_vc_Status”的约束、列、索引或触发器。不允许重复名称。

我对 mysqlServer 不是很有经验,我试图找出我的代码有什么问题。

CREATE TABLE vc_VidCast (
    -- Columns for the VidCast table
    vc_VidCastID int identity,
    VidCastTitle varchar(50) not null,
    StartDateTime datetime,
    EndDateTime datetime, 
    ScheduleDurationMinutes int,
    RecordingURL varchar(50),
    vc_UserID int not null,
    vc_StatusID int not null,
    -- Constraints on the VidCast List table
    CONSTRAINT PK_vc_VidCast PRIMARY KEY (vc_VidCastID),
    CONSTRAINT FK1_vc_VidCast FOREIGN KEY (vc_UserID) REFERENCES vc_User(vc_UserID),
    CONSTRAINT FK2_vc_VidCast FOREIGN KEY (vc_StatusID) REFERENCES vc_Status(vc_StatusID)
)
-- End creating the VidCast table


-- Creating the Status table
CREATE TABLE vc_Status (
    -- Columns for the Status table
    vc_StatusID int Identity,
    StatusText varchar(20),
    -- Constraints on the Status Table
    CONSTRAINT PK_vc_Status PRIMARY Key (vc_StatusID),
    CONSTRAINT U1_vc_Status UNIQUE (StatusText),
    CONSTRAINT PK_vc_Status FOREIGN KEY (vc_StatusID) REFERENCES vc_VidCast(vc_StatusID)

)
-- End Creating The Status Table

标签: sql-server

解决方案


推荐阅读