Sei sulla pagina 1di 2

Database: shared, integrated computer structure that stores a collection of data

End-user data; Business Data


Raw facts of interest to the end user, business
Metadata: data about data
Metadata provides description of data characteristics and relationships in data
Complements and expands value of data
Field: a column of data
Record: a row containing data in all columns for one entity such as a row for all customer data
Values: data in each cell.
File: a collection of related records, e.g., a table for all customers.
Structured Query Language (SQL) is the de facto query language
Entity: Unique and distinct object used to collect and store data
Attribute: Characteristic of an entity
Relationship: Describes an association among entities
Nouns translate into entities
Verbs translate into relationships among entities
Relationships are bidirectional
Entity instance (or occurrence) is row in table
Entity set is collection of like entities
Based on a relation
Relation or table: Matrix composed of intersecting tuple and attribute
Tuple: Rows
Attribute: Columns
Examples of Entity Sets: Customers, Students
Example of Entity Instance: Jane Lee
Composite key -Composed of more than one attribute
GRADES (Student-ID, Class-Code, Grade)
Superkey - Any key that uniquely identifies each row but has unnecessary attributes.
STUDENT (Student-ID, Last_Name, GPA)
Candidate key - An alternate primary key
Foreign key (FK) - An attribute whose values match primary key values in the related table
Unary relationship: Association is maintained within a single entity
Recursive relationship: Relationship exists between occurrences of the same entity set
Binary relationship: Two entities are associated
Ternary relationship: Three entities are associated
STUDENT(Student-ID, Student-Name, Class-Code, Grade)
QUESTION: What normal form is the above table in?
ANSWER: It is not normalized at all (or it is in 0NF) because It has multi-valued attributes: i.e., given one student ID, that student could have
multiple Class-Codes and Grades. Thus Class-Code and Grade are multi-valued attributes.
ENROLLMENT(Student-ID, Class-Code, Class-Title, Grade)
QUESTION: What normal form is the above table in?
ANSWER: It is in 1NF because: It has a primary key and no multi-valued attributes. However, this table is not in 2NF since it has a partial
dependency (i.e., Class-Title depends on Class-Code only, which is part of the key).
CLASS (Class-Code, Class-Title, Instructor-ID, Instructor-Name)
QUESTION: What normal form is the above table in?
ANSWER: It is in 2NF because: (1) It has a PK and no multi-valued attributes. (2) It has no partial dependencies. It's not in 3NF because it has a
transitive dependency -- Instructor-Name depends on Instructor-ID.
Normal Form
1NF: A table is in 1NF if: the table has a primary key and contains no multi-valued attributes.
2NF: A table is in 2NF if: the table is in 1NF and contains no partial dependencies.
3NF: A table is in 3NF if: the table is in 2NF and contains no transitive dependencies. (When a non-key attribute depends on another non-key
attribute, it is called a transitive dependency.)
Superkey an attribute (or combination of attributes) that uniquely identifies each row in a table
Candidate key a minimal (irreducible) superkey. A superkey that does not contain a subset of attributes than is itself a superkey.
Primary key a candidate key selected to uniquely identify all other attribute values in any given row.
Secondary key an attribute (or combination of attributes) used strictly for data retrieval purposes
Foreign key an attribute (or combination of attributes) in one table whose values must either match the primary key in another table or be null
Entity Integrity
Requirement all primary key entries are unique, and no part of a primary key may be null
Purpose each row will have a unique identity, and foreign key values can properly reference primary key values.
Example No invoice can have duplicate number, nor can it be null. In short, all invoices are uniquely identified by their invoice number.
Referential Integrity

Requirement a foreign key may have either a null entry, as long as it is not part of its tables primary key, or an entry that matches the primary
key value in a table to which it is related.
Purpose It is possible for an attribute not to have a corresponding value, but it will be impossible to have an invalid entry. The enforcement of
the referential integrity rule makes it impossible to delete a row in one table whose primary key has mandatory matching foreign key values in
another table
Example A customer might not yet have an assigned sale rep (number), but it will be impossible to have an invalid sales representative
(number)
CUSTOMERS (Customer#; First Name, Last Name, Address, Order#, Amount Due)
ORDERS (Order#, Order Date, Order Total in $ )
PRODUCTS (Product#, Product Name, Quantity On hand)
ORDER-LINE (Order#, Product#, product name, quantity ordered)
1. Which of the following tables has a composite key?
(a) CUSTOMER (b) ORDERS (c) PRODUCTS (d) ORDER-LINE
2. Which of the following is a weak entity?
(a) CUSTOMER (b) ORDERS (c) PRODUCTS (d) ORDER-LINE
3. Which of the following pairs of tables have a strong or identifying relationship?
(a) CUSTOMER and ORDERS (b) ORDERS and PRODUCTS
(c) ORDERS and ORDER-LINE (d) none of the above
4. Which of the following is a multi-valued attribute in CUSTOMER table?
(a) customer# (b) customer name (c) order# (d) none of the above
5. Which of the following would be the most appropriate PK for a SUPPLIER table?
(a) Supplier-ID (b) Supplier-Name (c) a combination of supplier ID and supplier name (d) supplier phone number (e) none of the
above
6. To create a relationship between CUSTOMER and ORDERS tables, what would you do?
(a) include Customer# column in ORDERS table as a FK column
(b) include Order# column in CUSTOMER table as a FK column
(c) include Order# column in CUSTOMER table and Customer# column in ORDERS table
(d) combine the two tables
7. Which of the following is a FK column in ORDER-LINE table?
(a) Order# (b) Product# (c) both a and b above (d) neither is a FK column in ORDER-LINE
8.
Which of the following attributes in the customers table is a composite attribute?
(a) Customer# (b) First Name (c) Address (d) Amount Due
9.
Which of the following tables has a composite primary key?
(a) customers (b) orders (c) order-line (d) products (e) none of the above
10.
What normal form is the ORDER-LINE table in? (a) 0NF (b) 1NF (c) 2NF (d) 3NF
11.
What normal form is the ORDERS table in? (a) 0NF (b) 1NF (c) 2NF (d) 3NF
12.
Which of the following functional dependence is not valid in a typical business environment?
(a) invoice# --> customer# (b) invoice# --> invoice date (c) invoice# --> product-code
13.
In a unary relationship, the relationship is between/among the instances of:
( a) two entities (b) one entity (c) three entities
14.
Is the relationship between ORDERS and ORDER-LINE tables in the above database
strong? (a) yes (b) no
15.
Are ORDERS and PRODUCTS tables union compatible? ? (a) yes (b) no
16.
Can we perform an inner join of CUSTOMERS and ORDERS tables? (a) yes (b) no
17.
What normal form is the CUSTOMERS table in? (a) 0NF (b) 1NF (c) 2NF (d) 3NF