I would like to know how to create a composite primary key in a weak relationship.
I mean, I create the two relationship tables and I do not know how to "pull" the primary key for the weak table. Should I pull it as foreign key before and only then create the composite key?
Would that be, for example?
Create Table TabelaForte(
Idforte Integer Identify(1,1) not null,
Nome Varchar(50) not null,
Descrição Varchar(50) not null,
)
Create Table TabelaFraca(
Idfraco Integer Identify(1,1) not null,
Atributo1 Varchar(50) not null,
Atributo2 Varchar(50) not null,
)
ALTER TABLE TabelaForte
ADD (PRIMARY KEY (Idforte));
ALTER TABLE TabelaFraca
ADD (FOREIGN KEY(Idforte) REFERENCES TabelaForte);
ALTER TABLE TabelaFraca
ADD CONSTRAINT chave_composta PRIMARY KEY CLUSTERED (Idforte, Idfraco)