3

我有三张桌子

Create table PROPERTY(
    property_number     int,
    property_name       int,
    property_type       varchar(30),
    property_street     varchar(30),
    property_city       varchar(30),
    property_zip        int,
    constraint PK_PROPRETY_NUMBER primary key(property_number)
)

Create table SERVICE(
    service_ID              int,
    service_description     varchar(150),
    service_amount          money,
    constraint PK_SERVICE_ID primary key(service_ID),
)

Create table SERVICEHISTORY(
    service_ID          int,
    service_date        date,
    property_number     int,
    constraint PK_SERVICEHISTORY_ID primary key(service_ID, service_date),
    constraint FK_SERVICE_ID foreign key(service_ID)
            references SERVICE(service_ID),
    constraint FK_PROPERTY_NUMBER foreign key(property_number)
            references PROPERTY(property_number)
)

我成功运行了前两个,它们出现在“表”下的对象资源管理器中。在 SERVICEHISTORY 中,“引用 SERVICE”和“PROPERTY”是错误的。当我运行该脚本时,我得到:

Msg 1767, Level 16, State 0, Line 11
Foreign key 'FK_SERVICE_ID' references invalid table 'SERVICE'.
Msg 1750, Level 16, State 0, Line 11
Could not create constraint. See previous errors.

这里发生了什么?

4

0 回答 0