0% found this document useful (0 votes)
278 views

Question 1

The document describes an object relational schema for a Movie database including object types for Theatre, Star, Film, and Showing as well as tables for Theatres, Films, and Showing. It provides sample SQL for creating the object types and tables, inserting sample data, and poses four questions about writing SQL queries on the schema.

Uploaded by

nagarjunapurum
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
278 views

Question 1

The document describes an object relational schema for a Movie database including object types for Theatre, Star, Film, and Showing as well as tables for Theatres, Films, and Showing. It provides sample SQL for creating the object types and tables, inserting sample data, and poses four questions about writing SQL queries on the schema.

Uploaded by

nagarjunapurum
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Question 1

Consider the following object relational schema for a Movie database:

Object types:
Theatre_t (tno:integer, name:string, city:string, phone:string)
Star_t (name:string, gender:char(1), birthdate:date)
Stars_nt table of Star_t
Film_t (filmno:integer, title:string, language:string, director:string, budget:float, stars stars_nt)
Show_t (film ref film_t, theatre ref theatre_t, startdate:date, enddate:date)

Tables:
Theatres of theatre_t (tno primary key)
Films of film_t (filmno primary key) Nested table stars store as stars_ntb
Showing of show_t (film references films, theatre references theatres)

The Theatres table has attributes of theatre number (tno), name, city and phone. It contains tuples for all theatres.
Films table contain tuples for all films, and has the attributes film number (filmno), title, language of the film,
director’s name (director), budget in dollars (budget), and stars of the film. The stars nested table consists of the
attributes name, gender (M=male and F=female) and date of birth. The Showing table contains a tuple for each
theatre and a film it shows, along with the start date (startdate) and end date (enddate). The attribute types are
specified in the type descriptions above, as also are the primary keys and referential constraints in the table schema.
Write Oracle Object SQL for these questions.
(a) Write Oracle object SQL to insert an object to film table. Use appropriate sample data fit into data
types.

(b) Display the names of female stars who have acted in films that are currently successful. Assume that a
successful current film has an average show period of 100 days or more at each theatre where it is being screened
now (current screening is indicated by enddate value of null). Subtracting a date d1 from another date d2 (where
d1<d2) gives the duration between them in days as a positive integer. Use sysdate for current date.

(c) For each theatre, find the title of film(s) that played for the longest period (i.e. the longest unbroken
period). Display the theatre name, city and the title of the film. Subtracting a date d1 from another date d2 (where
d1<d2) gives the duration between them in days as a positive integer.

(d) Write Oracle SQL for implementing a member method on theatre_t that returns the number of films a
given theatre is currently showing. The films currently being shown at a theatre are indicated by an enddate of null
in the Showing table. (Remember that each method specification in the type body is a PL/SQL block and it can
contain select statements on other tables of the database.)

Answers:

Theater Object Type


CREATE TYPE theater_t AS OBJECT (
tno INTEGER,
name VARCHAR2(25),
city VARCHAR2(15),
phone VARCHAR2(10)
);

Theater Table
CREATE TABLE theater OF theater_t (
tno PRIMARY KEY
);

Insert data to Theater table


INSERT INTO theater VALUES (theater_t (111,'Cineplex', 'Colombo', '0112345678'));
INSERT INTO theater VALUES (theater_t (112,'Regal', 'Gampaha', '0334123123'));
INSERT INTO theater VALUES (theater_t (113,'Vista', 'Jaela', '0114567894'));
INSERT INTO theater VALUES (theater_t (114,'Tower', 'Moratuwa', '0113456233'));
INSERT INTO theater VALUES (theater_t (115,'Savoy', 'Colombo 6', '0115321243'));

Star Object Type


CREATE TYPE star_t AS OBJECT (
name VARCHAR2(25),
gender CHAR(1),
birthday date );
Star Nested Table
CREATE TYPE stars_nt table of star_t;

Film Object Type


CREATE TYPE film_t AS OBJECT(
filmno INTEGER,
title VARCHAR2(20),
language VARCHAR2(10),
director VARCHAR2(25),
budget FLOAT,
starts stars_nt
);

Film Table
CREATE TABLE film OF film_t (
filmno PRIMARY KEY
)
NESTED TABLE stars STORE AS stars_nt;

Insert data to Film table


INSERT INTO film VALUES (
film_t (
110,'Joker', 'English', 'Todd Phillips', 3.5, stars_nt(star_t(‘st101’, 'F', '03-11-1989'))));

INSERT INTO film VALUES (


film_t (
111,'Bigil', 'Tamil', 'Atlee', 9.5, stars_nt(star_t(‘st102’, 'M', '10-01-1980'))));
INSERT INTO film VALUES (
film_t (
112,'Badla', 'Hindi', 'Sujoy Ghosh', 4.5, stars_nt(star_t(‘st103’, 'M', '12-11-1970'))));

INSERT INTO film VALUES (


film_t (
113,'Bharat', 'Hindi ', 'Ali Safar', 2.5, stars_nt(star_t(‘st104’, 'M', '10-11-1952'))));

INSERT INTO film VALUES (


film_t (
114,'Spider Man', 'English ', 'Jon Watts', 3.5, stars_nt(star_t(‘st105’, 'F', '10-11-1960'))));

Show Object Type


CREATE TYPE show_t AS OBJECT(
film REF film_t,
theater REF theater_t,
startdate DATE,
enddate DATE
);

Show Table
CREATE TABLE show of show_t(
film REFERENCE films,
theater REFERENCE theaters
);

b)

You might also like