1516 Exam SQL February SOLUTION
1516 Exam SQL February SOLUTION
First Name:
Second Name:
Departamento de Ingenierías
DNI.:
ELÉCTRICA y de SISTEMAS Y
AUTOMÁTICA Signature:
I. Write the Transact SQL code necessary for creating the following DB table named Apps: (35 points)
(Escribe el código en Transact SQL necesario para crear la siguiente tabla en la base de datos llamada Apps)
Name String of max length 60. This value must be necessarily ‘Gravity Panda’, ‘Fluffy Hen’, ‘Evernote’
provided. It has to be a unique value in the table.
CompanyName String of max length 60. This value must be necessarily. It is a ‘EA’, ‘Apple’, ‘OMDSource’
foreign key of the Companies table referencing its primaryKey
CompName.
TypeApp String of fix length 3. It can not be null. All characters must be ‘GAM’, ’PRO’, ‘CAS’
upper case letters (A-Z)
Price Money value. Default value is 0.0 It can not be negative. 2.99, 0.0, 50.99
Store String of max length 20. It can not be null. The unique posible ‘AppStore’,’Both’, ‘PlayStore’
values are ‘AppStore’, ‘PlayStore’, and ‘Both’
Date_of_publish Date of publish. It can not be a higher date than the current date. ‘2015/01/03’, ‘2002/12/11’
It can be null.
AppId Integer. Autoincremental value which start in 0 and has an step 0, 100, 200, 300,…
of 100. It is the primary key.
II. This question relates to the Northwind database (See over for its E-R diagram). Write an SQL query to show
the CategoryName and the Description of all the product Categories which has a Supplier from the country
‘Italy’. (35 points).
Notes:
1. Each product has an specific category.
2. You must use 3 tables in your query.
1
(Esta pregunta está relacionada con la base de datos Northwind (Mirad el diagrama E-R). Escribid una consulta SQL para
obtener el CategoryName y el Description de Categories, de los productos que son vendidos por Suppliers cuyo Country es
‘Italy’
Notas:
1. Cada producto tiene una categoría.
2. Se deben usar tres tablas en la consulta.
III. This question relates to the Northwind database (See its E-R diagram). Write a stored procedure named
AverageDiscount that shows the average discount of Order Details for a specific ProductID passed as
parameter (ProductID is an integer). Then, write the SQL sentence that invokes the stored procedure and that
passes it the actual input parameter 102. (30 points).
(Esta pregunta está relacionada con la base de datos Northwind (Mirad el diagrama E-R). Escribid un procedimiento
almacenado llamado “AverageDiscount” que muestre el descuento medio (discount) de [Order Details] cuyo ProductID sea
el que se pasa como parámetro al procedimiento (ProductID es un entero). A continuación, escribid la sentencia SQL que
invoca este procedimiento almacenado, pasándole como parámetro el valor 102.
CREATE PROCEDURE AverageDiscount @productID int
AS
SELECT AVG(Discount)
FROM [Order Details]
WHERE ProductID =@productID
RETURN
EXEC AverageDiscount 102
2
NORTHWIND Database
Schema