8.5
Consider the E-R diagram in Figure 8.7 showing entity set instructor. Give an SQL schema definition corresponding to the E-R diagram, treating phone_number as an array of 10 elements, using Oracle or PostgreSQL syntax.
The following uses Postgresql.
CREATE TYPE nameType AS (
VARCHAR(15),
first_name CHAR,
middle_initial VARCHAR(15)
last_name
);
CREATE TYPE streetType AS (
VARCHAR(15),
street_name VARCHAR(4),
street_number VARCHAR(7)
apartment_number
);
CREATE TYPE addressType AS (
street streetType, VARCHAR(15),
city VARCHAR(15),
state CHAR(6)
zip_code
);
CREATE TABLE instructor (
id integer primary key,
name nameType,
address addressType, VARCHAR(12)[],
phone_number date
date_of_birth );
If you are curious how to insert data into the instructor relation in postgresql, use the following:
INSERT INTO instructor VALUES (
1,
'Michael', '-', 'Faraday')::nameType,
(NULL, NULL, NULL)::streetType, 'Newington Butts', 'England', NULL)::addressType,
((ARRAY['+111-555-333', '+333-222-777'],
'1791-9-22'
);