1516 Exam SQL January SOLUTION
1516 Exam SQL January SOLUTION
First Name:
Second Name:
Departamento de Ingenierías
DNI.:
ELÉCTRICA y de SISTEMAS Y
Signature:
AUTOMÁTICA
I. Write the Transact SQL code necessary for creating the following DB table named Films: (35 points)
(Escribe el código en Transact SQL necesario para crear la siguiente tabla en la base de datos llamada Films)
Name String of max length 60. This value must be necessarily ‘Lo que el viento se llevó’, ‘Matrix II’, ‘A-Cuerdos’
provided and (Name, DirectorID) is the primary key
DirectorID String of max length 60. This value must be necessarily ‘Luis Buñuel’, ‘Steven Spielberg’, ‘El fary’
provided (Name, DirectorID) is the primary key. It is a foreign
key of the Directors table referencing its primaryKey DirId.
Date_of_premiere Date of the premiere. It can not be null and the default value is ‘15/01/2015’,’03/10/2002’
the current date.
FilmLength Integer with the length in minutes of the film. The value can 90, 100, 120
not be negative and can not be bigger than 200. It can be null
FilmNumber Number which store the inserted order into the dataset. It has 1,2,3,4,…
to be an auto incremental value.
FilmRank Number between 0 and 99 with two decimals digits This value 54.75, 99.99, 4.12
must be >=0 and can be null
II. This question relates to the Northwind database (See over for its E-R diagram). Write a SQL query to obtain
the Phone of all the Customers who made an Order using the Shipper “Speedy Express”and also the name
and last name of the employees who carried out the sales (35 points).
Notes:
1. Orders.ShipVia is the foreign key of the Shippers table.
2. The name of the Shipper is specified in the field Shippers.CompanyName.
3. You should use JOIN operations.
1
4. The output must contain three columns: Customers.Phone, Employees.Name and
Employee.LastName.
(Esta pregunta está relacionada con la base de datos Northwind (Mirad el diagrama E-R). Escribid una consulta SQL para
obtener el Phone de todos los Customers que hayan realizado algún pedido a través de la shipper “Speedy Express” y además
el nombre y apellidos de los vendedores que realizaron las ventas.
Notas:
1. Orders.ShipVia es la clave ajena de la tabla Shippers.
2. El nombre de la empresa de envío es especificado en el campo Shippers.CompanyName
3. Se recomienda utilizar operadores JOIN para realizar la consulta
4. La salida debe estar formada por tres columnas: Customers.Phone, Employees.Name y Employee.LastName
III. This question relates to the Northwind database (See its E-R diagram). Write a stored procedure named
TotalPrice that shows the multiplication of [Order Details].UnitPrice and [Order Details].Quantity which
discount is equal to the real number that gets passed to the procedure sorted by the OrderID field ins
ascending order . Then, write the SQL sentence that invokes the stored procedure and that passes it the actual
input parameter 0.15. (30 points).
(Esta pregunta está relacionada con la base de datos Northwind (Mirad el diagrama E-R). Escribid un procedimiento
almacenado llamado “TotalPrice” que muestre la multiplicación de [Order Details].UnitPrice y [Order Details].Quantity
cuyo descuento sea igual al valor real que se pasa como parámetro ordenados por el campo OrderID de manera ascendente.
A continuación, escribid la sentencia SQL que invoca este procedimiento almacenado, pasándole como parámetro el valor
0.15.
CREATE PROCEDURE TotalPrice @discount real
AS
SELECT UnitPrice*Quantity
FROM [Order Details]
WHERE discount =@discount
ORDER BY OrderID asc
RETURN
EXEC TotalPrice 0.15
2
NORTHWIND Database
Schema