i’m just starting with SQL, i have an assignement to do that involves a relational scheme to SQL tables.
I have a big doubt on how to represent the following:
I have the table “Original” that is represented by the following SQL:
create table Original (
idB char(10) not null unique,
tituloM varchar(255) not null,
primary key (idB, tituloM),
foreign key (idB, tituloM) references Musica on delete cascade on update cascade
);
I now have to represent the table “Live” that has the following relational representation:
Live(idB; tituloM; data; hora; tituloMO), where idB and tituloMO are foreign keys to “Original”. My doubt is, we don’t have a “tituloMO” in the “Original” table. How can i represent this ? Currently my “Original” table looks like this:
create table Live (
idB char(10) not null unique,
tituloM varchar(255) not null,
/* date goes here */
/* time goes here */
tituloMO varchar(255) not null,
primary key (idB, tituloM),
foreign key (idB, tituloM) references Musica on delete cascade on update cascade,
foreign key (idB, data, hora) references Concerto on delete cascade on update cascade,
foreign key (idB, tituloMO)
);
How can I represent the tituloMO field correctly?
When you make a
FOREIGN KEYreference, you don’t need for the corresponding columns to have same names, only compatible datatypes.So, your constraints would be: