Ir para conteúdo
Fórum Script Brasil

Rafa Alves

Membros
  • Total de itens

    1
  • Registro em

  • Última visita

Sobre Rafa Alves

Rafa Alves's Achievements

0

Reputação

  1. bom dia! Sou iniciante em banco de dados SQL Server e estou criando um banco de dados exemplo sobre hospedagem. Estou travado pois das 3 FKs que possuo na tabela Reserva, eu não estou conseguindo adicionar a FK Nr_quarto, pois dá um erro: "Msg 1776, Level 16, State 0, Line 112 There are no primary or candidate keys in the referenced table 'Quarto' that match the referencing column list in the foreign key 'FK_Reserva_Quarto' Por favor poderiam me auxiliar? create table Quarto ( Nr_hotel INT not null, Nr_quarto INT not null, Cd_tipo CHAR(2) not null, CHECK (Cd_tipo IN('1', '2')), Vl_preço INT not null PRIMARY KEY (Nr_hotel, Nr_quarto) ) go create table Reserva ( Nr_reserva INT IDENTITY, Nr_hotel INT not null, /*FK*/ Nr_quarto INT not null, /*FK*/ Dt_inicio DATE not null, Dt_fim DATE, Nr_hospede INT NOT NULL, /*FK*/ PRIMARY KEY (Nr_reserva) ) go ALTER TABLE Reserva ADD CONSTRAINT FK_Reserva_Quarto FOREIGN KEY(Nr_quarto) REFERENCES Quarto(Nr_quarto) GO ALTER TABLE Reserva ADD CONSTRAINT FK_Reserva_Hospede FOREIGN KEY(Nr_hospede) REFERENCES Hospede(Nr_hospede) GO ALTER TABLE Reserva ADD CONSTRAINT FK_Reserva_Hotel FOREIGN KEY(Nr_hotel) REFERENCES Hotel(Nr_hotel) GO
×
×
  • Criar Novo...