Part 1 Flashcards
Give a brief explanation of the difference between the rerms information and data.
Information is any kind of knowledge that is interpretable by people in some context. Data is a representaion of information; it has no meaning without a context.
Give a sentence that represents your understanding of the information content of the form.
The cource with the title “Relational Databases: theory and practice” has code M359, cource manager John Sykes and 618 students enrolled on it.
“Students enrolled” on the form is an example of devirred data. Explain what this means in terms of data in a database.
The value for “Student enrolled” is a dirrived data becouse it is calculated from other data in the database.
State the number of occurences of the Supplies relationship shown in Figure 1.
5 ( the number of occurrence lines).
What can you deduce about the degree and participation conditions of the Supplies relationship based on the occurrences given?
The participation of the Supplier in the relationship is optional. An occurence of Supplier may be related to many occurrences of Part via the Supplier relationship.
“The participation of the Supplier in the relationship is optional. An occurence of Supplier may be related to many occurrences of Part via the Supplier relationship.”
draw an E-R diagram showing the Supplies relationship between the two entities typesSupplier and Part.
relation Staff
StaffNumber: StaffNumbers
Name: Names
primary key StaffNumber
relation Computer
Code: Codes
Type: Types
primary key Code
relation IsAssigned
StaffNumber: StaffNumbers
Code: Codes
primary key StaffNumber
foreign key StaffNumber references Staff
alternative key Codes
foreign key Code references Computer
Write down relational algebra epressions;
Each staff member is associated with at least one task
constraint ((project Staff over EmployeeNumber)
difference
(project Task over EmployeeNumber))
isEmpty
A staff member can be associated with a secretarial task only if his/her grade is 2 or above.
constraint
(select Staff join Task where Grade > 1 and TaskType = Secretarial)
is empty
Demonstrate that Vets has no functional dependencies with determinant PersonName and with the right-hand side consisting of a single attribute.
PersonName>Vet? No, because e.g. Barker is associated with two values of Vet.
PersonName>AnimanName? No, because e.g. Ahmad is associated with animals with names Fluffy and Tiger.
PersonName>AnimalType? No, Because e.g. Barker is associated with both a dog and a horse.
Consider the following decomposition of Vets into the relations Vets1 and Animals:
Vets1 alias (project Vets over Vet, PersonName, AnimalName)
Animals alias (project Vets over AnimalName, AnimalType)
Is this a non-lossy decomposition?
The first decomposition gives a relation which can be depicted by the first three columns of the table; the second gives a relation which can be depicted by the last two columns, When we join these two decompositions together, we get the following tuples.
The second tuble depicted was not in the orginal relation, so this is a lossy decomposition - the information that the second tuple is not part of Vets is lost.
Consider the following relation R with functional dependecies as shown;
R(a, b, c, d)
a,b -> c
a,b -> d
a -> c
Is R in third normal form?
R is not in second normal form because of a -> c. ( That is, c is not fully functionally dependent on the primary key.)
So R cannot be in third normal form as it is not even in second normal form.
SELECT b.a1, b1
FROM a,b
WHERE b.a1 = a.a1
AND a2 > 500
SELECT a1, a2
FROM a
WHERE (SELECT COUNT(*)
FROM b
WHERE b.a1 = a.a1)<2
SELECT c2, f
FROM c, (SELECT b2, COUNT(*) AS f
FROM b
GROUP BY b2) AS t1
WHERE b2 = c1
List the membership number, name and date of birth of each member for whom date of birth has been stored
SELECT member_no, name, date_of_birth
FROM member
WHERE date_of_birth IS NOT NULL
Give the membership number and name of each member who is currently borrowing one oe more CDs.
SELECT DISTINCT member.member_no, name
FROM member, loan
WHERE member.member_no=loan.member_no
For each member of the library, list his or her membership number and the number of CDs that he or she is currently borrowing. Your solution should show 0 as the number of CDs borrowed for members who are not currently borrowing CDs.
SELECT member.member_no, COUNT(cd_name) AS
number_borrowed
FROM member LEFT OUTER JOIN loan
ON member.member_no=loan.member_no
GROUP BY member.member_no
The administrator of the CD library has defined a procedure make_loan. The definition contains the declaration: make_loan(IN member_nos, IN cs_names)
where member_nos and CD_names are the domains of membership numbers and CD name, respectively. When make_loan is called, a row is added to the loan table containing the membership number of the member borrowing the CD, the name of the CD and the return date, which is calculated by the procedure.
Give two reasons why using this procedure may be preferable to wrking directly with the loan table.
Access conrol: A user can be given access to the procedure, but not have any access privilages to the underlying tables.
Ease of use: The procedure means that the processing (calculation of the return date, and statements relating to the specific tables) cab be hidden from the user.
In addition to the make_loan procedure, a function items_borrowed is define which returns the number of the CD that a member has borrowed. Its signatures is
items_borrowed (IN member_nos) RETURNS INTEGER
A member is allowed to borrow up to 3 CDs. The member with membership number m48 wishes to borrow “Best of Bach” and “Magic of Mozart”.
You are required to write a transaction which either successfully completes with the member borrowed more than 3 CDs. You should use the procedure make_loan and the function items_borrowed to answer this question.
BEGIN
CALL make_loan(‘m48’, ‘Best of Bach’);
CALL make_loan(‘m48’, ‘Magic of Mozart’);
IF items_borrowed(‘m48’) > 3
THEN ROLLBACK WORK;
ELSE COMMIT WORK;
END IF;
END
Entity-relationship diagram
Entity types
Additional constraints
Assumptions
Limitations
Entity types
Employee(StaffNo, Names_)_
Book(ISBN, Title, Author, Cost)
Reservation(StaffNo, ISBN, DateReserved)
Additional consttaints
c. 1 Reservation is a weak entity tyoe dependent on the entity type Employee. So each value of the StaffNo attribute in the entity type Reservation must be the same value as the StaffNo attribute of the Employee instance to which the Reservation entity type is related by the relationship Makes(a consequence of weak-strong entity types).
c. 2 Reservation is a weak entity type dependent on the entity type Book. So each value of the ISBN attribute in the entity type Reservation must be the same value as the ISBN attribute of the Book onstance to which the Reservation entity type is related by the relationship IsForA (a consequence of the weak-strong entity types.)
Assumptions - None
Limitations - None
Give three reasons why it may be necessary to restructure a database after it has been built and installed.
- Correcting errors or omissions in the database design and/or implementing that remained undetected after acceptance testing.
- Optimising performance.
- Satisfying new and changing requirements.
Give two reasons why denormalisation is not usually performed unless a performance need arises.
Denormalisation results in duplicated information which (1) may require more disk space to store (2) may result in insertion, amendment and deletion anomalies if the duplicated information needs to be updated.
What do (i) OLAP and (ii) OLTP systems facilitate within an organisation?
i. OLAP systems enable decision makers to gain insight into an organisation’s data from different, and multiple, perspectives.
ii. OLTP systems support the day-to-day operations of an organisation, such as purchasing, inventory, manufacturing, banking, payroll and accounting.
Brefly wsplain what is meant by the term ‘time variant’ for a data warehouse, and describe the main consequence of this in terms of multi-dimensional model.
The term ‘time variant’ means that historical data is recorded. Time is always one of the dimensions of a multi-dimensional model.
Give one reason why it is customary to implement a data warehouse seperately from the operational systems that are the source of its data.
Processing conflicts (queries vs updating).
Different organisation of data.
No historical data in operational systems.
Multiple sources/formats.
Briefly describe a document type definition and a document type declaration, making clear the distinction between the two terms.
A document type definistion is a set of markup declerations that define a document type and its structure.
A document type decleration is an instruction to assosiate XML within document type definision.
Explain why neither of these two terms (document type declaration, document type definition) is relevant to the XML data types as defined by SQL/XML.
The XML data type as defined by SQL/XML has a value that is a well-formed (i.e. parsable) XML document, which does not require a document type declaration or associated DTD; if one is included, its not in use.
Java host variables are different from host variables in other programming languages for which embedded SQL can be used becouse they:
a. are not specified in a declare section.
b. do not require the prefix: in embedded SQL statements.
c. cannot be used in host language statements.
a. are not specified in a declare section.
JDBC implicitly establishes a cursor after executing the method:
a. getConnection
b. createStatement
c. executeQuery
c. executeQuery
To optain a value from the current wor of a JDBC result set, you have to use a get method with:
a. the column number.
b. the data type of the column in the database.
c. the data type of the result.
c. the data type of the result.
If the prepareStatement methid is executed for an SQL query containing a parameter marker, the query can be executed:
a. imediately.
b. after a value has been set for the parameter marker.
c. after a database connection is estalished.
b. after a value has been set for the paremeter marker.
An object-relational mapping tool enables a Java program to access a database without writing SQL by:
a. using mapping schema to translate classes to tables.
b. using Java procedures stored in the database.
c. using a pre-compiler to translate Java to the native DBMS interface.
a. using a mapping schema to translate classes to tables.
Data Administrators, Database Administrators, Database Developers, Application Developers, End Users
a) … : in many cases will neither know, nor care, that a database is involved in meeting their needs.
b) … : will be responsible for translating the logical database design into a physical realisation within a specific DBMS product, balancing performance characteristics and physical storage option.
c) … : have responsibility for implementing the data use policies and conceptucal models as well as the day-to-day running of the database systems.
d) … : have a role that includes understanding the business requirements of the organisation and overseeing the planning and development of new data systems and the maintenance and control of existing systems.
e) … : are tasked with building or customising user processes (programs and utilities, report generators and query tools) to meet the specific requirements of the end users.
a) End users
b) Database Developers
c) Database administrators
d) Data Administrators
e) Application Developers
Consider the following part of a conceptual data model for annual shows, the
clubs that host them and the sponsors who fund the shows (Note that the E-R
diagram is incomplete).
a.)The relationship ‘FundedBy’ is not shown on the entity-relationship diagram
above. Complete the entity-relationship diagram above by showing the
relationship, representing the degree and participation conditions required to
meet the description given below:
Each AnnualShow is funded by zero or one Sponsors.
Each Sponsor supplies funding for one or more AnnualShows
AnnualShow(Year, Theme, Venue, SponsorName)
Consider the following part of a conceptual data model for annual shows, the
clubs that host them and the sponsors who fund the shows (Note that the E-R
diagram is incomplete).
b) Briefly explain why each of the following scenarios cannot be represented by
the conceptual data model for annual shows.
(i) The West Midlands show will be co-hosted by clubs in Birmingham,
(ii)A sponsor has agreed to sponsor the 2015 Milton Keynes annual show,
but the organisers are still looking for a club to host it in that year.
Solihull and Coventry.
(i) Because an attribute can only have 1 value, also IsHostFor states that each annualShow must have 1 club.
(ii) Value cannot be NULL, isHostFor states that each annual show must have 1 club.
(i) Give one reason why this table is not a relational table.
(ii) Represent the same information in a relational table and give the
primary key for the associated relation.
(i) The first row has two values under StaffManaged. A relational table can only have one value per attribute (only atomic values are allowed)/
(ii)
S1 Oxford S3
S1 OxforSaved S4
S2 Oxford S1
S5 London S2
primaryKey (EmployeeNumber, Location)
Complete the following relational representation so that it corresponds to the E-R
model above.
You may assume that suitable domains, StaffIds, ModuleCodes, StaffNames and
ModuleNames have already been defined.
Relation AcademicEditor
SfattId: StaffIds
StaffName: Staff Names
ModuleCode: Module Codes
Primary Key StaffId
{mandatory parcipation in Edits}
foreign key (ModuleCode) reference Module
{Edits 1:1}
Alternate key(ModuleCoede)
Relation Module
ModuleCode: ModuleCodes
ModuleName: Module Names
Primary key ModuleCode
Relation Writer
StaffId: staff ids
StaffName: staff names
ModuleCode: module codes
Primary key StaffId
{mandatory participation in Writers}
foreign key ModuleCode References Module
(a) Give the table that is returned by the following query, using the data in
Table 1.
SELECT part_no, supplier_name, stock_level
FROM part
WHERE price >= 75
(b) Give the table that is returned by the following query, using the data in Table 1.
SELECT part_no
FROM part
WHERE stock_level > (SELECT SUM(stock_level)
FROM part WHERE price >=75)
(c) Give the table that is returned by the following query, using the data in
Table 1.
SELECT supplier_name, COUNT(*) as how_many
FROM part
WHERE part_name <> ‘gearbox’
GROUP BY supplier_name
HAVING MIN(stock_level) = 50
(a)
p22 Newton 25
p35 Electra 30
(b)
p04, p07
(c)
suppliers_name | how_many
Newton | 1
Write SQL queries to answer the following requests.
(a) List the part number and part name for all parts whose supplier is located in
London.
(b) Give the total monetary value of all stock where stock levels are above 50.
(c) Give the names of suppliers who supply more than one part.
(a)
SELECT part_no, part_name
FROM part a, supplier b
WHERE location =’London’ AND a.supplier_name = b.supplier_name
(b)
SELECT SUM(price*stock_level) AS stock_monetary_value
FROM part
GROUP BY part_no, stock_level
HAVING stock_level >50
(c)
SELECT supplier_name
FROM (SELECT supplier_name, COUNT(supplier_name) AS sn_count
FROM part
GROUB BY supplier_name) AS supp_names
WHERE supp_names.sn_count>1
(a)
CREATE TABLE supplier
(supplier_name VARCHAR(25) NOT NULL,
location VARCHAR(25) NOT NULL,
PRIMARY KEY (supplier_name),
(b)
CREATE TABLE part
(part_no CHAR(3) NOT NULL,
part_name VARCHAR(25) NOT NULL,
supplier_name VARCHAR(25) NOT NULL,
stock_level INTEGER NOT NULL,
price INTEGER NOT NULL,
PRIMARY KEY (part_no),
(a)
CONSTRAINT supplier_parts
CHECK supplier_name IN (SELECT supplier_name FROM part);
(b)
CONSTRAINT fk_supplier_name
FOREIGN KEY supplier_name REFERENCES supplier;
CONSTRAINT part_no_valid
CHECK(part_no(SUBSTR(VALUE, 1, 1)= ‘p’) AND
(CAST(SUBSTR(VALUE,2,2) AS INT) BETWEEN 0 AND 99)));
The delivery company wants to record the estimated distance and estimated
journey time for each delivery from a depot to a customer.
In the space below produce a new conceptual model so that the additional
requirements of recording estimated distance and estimated journey time are
shown.
C.1 Delivery is a weak entity type dependent on Depot. So, each value of IdCode in the entity type Delivery must be the same value as the IdCode of the Depot Instance to which the Delivery entity type must related by the relationship Deliver(a consequence of weak-strong entity types).
C.2 Delivery is a weak entity type dependant on Customer. So each value of Reference of the entity type Delivery must be the same as value as the Reference of the Customer instance …
(a) Explain what is meant by denormalisation. What reason is usually given in
order to justify it?
(b) List the three types of anomalies that may arise after updating an
unnormalised table.
(a) Denormalisation is the process of merging tables that are associated by l:m relationships and the reason for this is usually to speed up the query process
(b) insertion, deletion and amendment
The following is a well formed tree of XML-elements containing some data about
a DVD library. This tree represents some details of a single DVD and the
recordings on the DVD (chapters).
Write down headings for relations that are capable of holding the same data as
the dvd_library XML structure. You should use two relational headings and
underline their primary keys, to allow the data for the details of several DVDs and
their chapters to be stored and recreated. Show how the above data would
appear in your relations.
(You can assume that the order of chapters on a DVD in the XML tree structure
does not need to be recreated).
dvd(catalogue_no, title, artist)
Chapters (chapter_no, title, dvd_cat_no)
dvd
catalogue_no | title | artist
B550361 | Spirited away | Hayao Miyazaki
chapters
chapter_no | title | dvd_cat_no
1 | midle of nowhere | B550361
2 | It’s just a dream | B550361
3 | Finding work | B550361
4 | Meeting Yubaba | B550361
Complete the following sentences by inserting appropriate words into the
underlined spaces, one per space, by choosing words from the following
list. The same word may occur more than once in the sentences. Not all
the words listed are used in the sentences.
Words: security, logical, many, distributed, four, three, two, mobile,
schema, data, index, storage, space, user, management,
representation, external, model, server, transfer, exchange,
interaction, mapping, property, replicated.
(i) The _____________-schema architecture is a general model of
database representation that places importance on the separation of
the ______________, _____________ and _____________
schemas.
(ii) In this model, data independence is achieved by _______________
between schema representations. Logical data independence is
provided by the _______________ between _____________ and
_______________ schemas.
(iii) In the _______________-schema architecture there can be many
_______________ schemas, but only a single ______________
and _______________ schema defined for a database.
(i) three, logical, storage, external
(ii) mapping, mapping, logical, external
(iii) three, external, logical, storage