Professional Documents
Culture Documents
Ejemplo de Examen Base de Datos
Ejemplo de Examen Base de Datos
Ejemplo de Examen Base de Datos
Answers to Exercise 1.
StartDate
PolicyNr Name
Name EndDate Technique
Century
N N
Exhibition Assigned Painting
N N
Holds Paints
Name BirthDate
1 1
4 1
Museum Painter
Teaches
Answers to Exercise 2.
StudentMail(SSN, eMail)
Tutors(Course, Tutor)
1
Answers to Exercise 3.
-- -----------------------------------------------------------------------------
-- 3.a
-- -----------------------------------------------------------------------------
-- -----------------------------------------------------------------------------
-- 3.b
-- -----------------------------------------------------------------------------
SELECT TFilm
FROM Film pe
JOIN Show pa USING (TFilm)
JOIN Room sa USING (codCinema,numRoom)
JOIN Cinema ci ON ci.cod = codCinema
WHERE pe.duration > 90
GROUP BY TFilm, ci.district
HAVING SUM(capacity) > 300;
-- -----------------------------------------------------------------------------
-- 3.c
-- -----------------------------------------------------------------------------
-- -----------------------------------------------------------------------------
-- 3.d
-- -----------------------------------------------------------------------------
2
SELECT codCinema
FROM Show
JOIN Film USING (TFilm)
WHERE EXTRACT(YEAR FROM releaseDate) = 2016
AND codCinema NOT IN (
SELECT codCinema
FROM Show
JOIN Film USING (TFilm)
WHERE EXTRACT(YEAR FROM releaseDate) != 2016);
-- -----------------------------------------------------------------------------
-- 3.e
-- -----------------------------------------------------------------------------
-- -----------------------------------------------------------------------------
-- 3.f
-- -----------------------------------------------------------------------------
BEGIN
DBMS_OUTPUT.PUT_LINE(’--------------------------------------------------’);
SELECT COUNT(*), ’Cinema: ’|| TRIM(p_Cinema)|| ’, Num of Rooms: ’ || COUNT(*)
|| ’, Total capacity: ’|| SUM(capacity)
INTO v_count,v_cinemaData
FROM Room
3
WHERE codCinema = p_Cinema;
IF v_count = 0 THEN
RAISE NO_DATA_FOUND;
END IF;
DBMS_OUTPUT.PUT_LINE(v_cinemaData);
DBMS_OUTPUT.PUT_LINE(’--------------------------------------------------’);
DBMS_OUTPUT.PUT_LINE(’ Time Room Film Avail.Seats’);
DBMS_OUTPUT.PUT_LINE(’--------------------------------------------------’);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE(’Cinema ’ || p_Cinema || ’ does not exist.’);
END;
/
-- -----------------------------------------------------------------------------
-- 3.g
-- -----------------------------------------------------------------------------
4
WHERE CodCinema = :OLD.CodCinema
AND NumRoom = :OLD.NumRoom
AND startTime = :OLD.startTime;
UPDATE Show
SET ticketsSold = ticketsSold + :NEW.numSeats
WHERE CodCinema = :OLD.CodCinema
AND NumRoom = :OLD.NumRoom
AND startTime = :OLD.startTime;
END IF;
END;
/
SELECT * FROM Room WHERE codCinema = 1 AND numRoom = 1 AND startTime = TO_DATE(’18:00:00’);
SELECT * FROM pases WHERE codCinema = 1 AND numSala = 1 AND Hora = TO_DATE(’18:00:00’);
SELECT * FROM Room WHERE codCinema = 1 AND numRoom = 1 AND startDate = TO_DATE(’18:00:00’);
SELECT * FROM Show WHERE codCinema = 1 AND numRoom = 1 AND startDate = TO_DATE(’18:00:00’);
SELECT * FROM Show WHERE codCinema = 1 AND numRoom = 1 AND startTime = TO_DATE(’18:00:00’);
5
Answers to Ejercicio 4.
-- -----------------------------------------------------------------------------
-- Given the table SALES(Title, TicketsSold), that initially is empty,
-- and the execution of the next sequence of sentences ( autocommit=
-- off)
-- a) Write the values of the column TicketsSold for each row in the
-- table Sales at each point denoted by step N -- (even though the
-- operations have not been committed)
-- d) At the end of the execution, How many tables would have been
-- created in the database?
-- -----------------------------------------------------------------------------
savepoint step_one;
INSERT INTO SALES VALUES (’My Fair Lady’, 200); -- b) Start of 1st transaction.
savepoint step_two;
update VENTAS
set TicketsSold = TicketsSold + 100
where Title = ’My Fair Lady’;
update VENTAS
set TicketsSold = TicketsSold + 200
where Title = ’My Fair Lady’;
rollback;
INSERT INTO VENTAS VALUES (’My Fair Lady’, 1000); -- b) Start of 2nd transaction.
update VENTAS
set TicketsSold = TicketsSold + 300
where Title = ’My Fair Lady’;
savepoint step_three;
commit;
-- (End of transaction. No active transaction).
6
-- Step 7 -- a) One row with values (’My Fair Lady’, 1300).