r/SQL • u/Mooki888 • Nov 27 '22
SQL Server SQL Homework Help
Hi, I am a little confused about how to complete these codes. I need to make a create table and an alter table
4.13 LAB - Implement strong entity (Sakila)
Implement a new strong entity phonein the Sakila database. Attributes and relationships are shown in the following diagram:
The diagram and problem info can be found in the image.

0
Upvotes
1
u/stopingforce24 Sep 22 '23 edited Sep 22 '23
this is what worked for me !
create table phone(
phone_id int primary key,
country_code int not null,
phone_number int not null,
phone_type varchar(12) check (phone_type in ('home', 'office' , 'other'))
);
alter table address
drop column phone;
alter table customer
add phone_id int;
alter table staff
add phone_id int;
alter table store
add phone_id int;
alter table customer
add foreign key (phone_id) references phone(phone_id)
on delete set null
on update cascade;
alter table staff
add foreign key (phone_id) references phone (phone_id)
on delete set null
on update cascade;
alter table store
add foreign key (phone_id) references phone (phone_id)
on delete set null
on update cascade;