0

我正在尝试创建两个简单的表,并且在外键上出现此错误。不知道为什么,我正在做的事情非常简单。也许只是我太新手了,看不到明显的东西。错误出现在“REFERENCES Empregado(CodEmp)”上

USE Zurrapa

if not exists (select * from dbo.sysobjects 
               where id = object_id(N'[dbo].[Empregado]') )
begin
  CREATE TABLE Empregado (
    CodEmp int NOT NULL 
        CHECK (CodEmp >= 1),
    Nome nvarchar (50) NOT NULL ,
    Função nvarchar (30) NOT NULL ,            
    Salario decimal(10,2) NOT NULL
        DEFAULT 0.0 
        CHECK (Salario >= 0.0)

    CONSTRAINT PK_CodEmp PRIMARY KEY (CodEmp)
  ); 
end

-- ............................................................................

if not exists (select * from dbo.sysobjects 
               where id = object_id(N'[dbo].[Bar]') )
begin
  CREATE TABLE Bar (
    CodBar int NOT NULL 
        CHECK (CodBar >= 1),                    
    LocalizaçãoBar nvarchar(30) NOT NULL,
    CodEmpResp int NOT NULL
        CHECK (CodEmpResp >=1)

    CONSTRAINT PK_CodBar PRIMARY KEY (CodBar), 
    CONSTRAINT LocalizaçãoBar UNIQUE (LocalizaçãoBar),
    CONSTRAINT FK_CodEmpResp FOREIGN KEY (CodEmpResp) 
        REFERENCES Empregado(CodEmp)
        ON UPDATE CASCADE 
  ); 
    
end
4

0 回答 0