You are on page 1of 2

-- Q1

CREATE VIEW view_d_songs AS


SELECT d_songs.id, d_songs.title "Song Title", d_songs.artist
from d_songs INNER JOIN d_types ON d_songs.type_code = d_types.code
where d_types.description = 'New Age';

SELECT d_songs.id, d_songs.title "Song Title", d_songs.artist


from d_songs INNER JOIN d_types ON d_songs.type_code = d_types.code
where d_types.description = 'New Age';

-- Q2

CREATE OR REPLACE VIEW view_d_songs AS


SELECT d_songs.id, d_songs.title "Song Title", d_songs.artist, d_songs.type_code
from d_songs INNER JOIN d_types ON d_songs.type_code = d_types.code
where d_types.description = 'New Age';

-- Q3

CREATE OR REPLACE VIEW line ("Department Id", "Max Salary", "Min Salary", "Average Salary") AS
SELECT d.department_id, MAX(NVL(e.salary,0)), MIN(NVL(e.salary,0)), ROUND(AVG(NVL(e.salary,0)),2)
FROM departments d LEFT OUTER JOIN employees e ON d.department_id = e.department_id
GROUP BY (d.department_id, d.department_name);

-- Q4

CREATE OR REPLACE VIEW view_copy_d_songs AS


SELECT title, artist
FROM copy_d_songs;

-- Q5

CREATE OR REPLACE VIEW READ_COPY_D_CDS AS


SELECT *
FROM copy_d_cds
WHERE year = '2000'
WITH READ ONLY ;

-- Q6

CREATE SYNONYM dj_tracks FOR d_track_listings;

-- Q7

CREATE TABLE students (

student_id number(5) PRIMARY KEY,


first_name VARCHAR2(10),
last_name VARCHAR2(15),
section number(4)
);

CREATE SEQUENCE student_id_seq


START WITH 0
MINVALUE 0
INCREMENT BY 1
;

INSERT INTO students


(student_id,first_name,last_name,section)
VALUES
(STUDENT_ID_SEQ.nextval,'Abdelhamid','Khald',2)
;

You might also like