Quiz 1 Flashcards

(43 cards)

1
Q

What is a database?

A
  • Collection of files
  • Predefined structure
  • Optimized for efficient retrieval
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How are databases different from data files?

A
  • Structure for efficient retrieval
  • Consistency: no contradictions
  • Computer crash: database handles it
  • Security
  • Concurrency
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

DBMS

A

Collection of programs that allow user to create, maintain, and query a database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the new philosophy regarding data and programs?

A

All about the data. Data is persistent, more important than the programs that access it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Four steps for building and using a relational databases

A
  1. Design the schema: database design
  2. Create the schema with DDL (data design language)
  3. Load the database with initial data
  4. Query and updates
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Example SQL for creation of schema

A

CREATE TABLE STUDENT(

NAME char(30)

SID Int NOT NULL

GPA float  );
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define a query

A

In a high level language, NOT an algorithm.

  • Easy to formulate
  • Just because a query looks easy does not mean efficient retrieval
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Difference between DDL and DML

A

DDL (Data design language): This handles the design of the database.

DML (Data Manipulation language): For queries and updates.

  • SQL can be used for both of these
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

List names and GPA of students greater than 32 using SQL

A

SELECT name,gpa FROM Student WHERE gpa > 3.2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Define the result of a query

A
  • The result is a TABLE (or a view)
  • It is closed mathematically
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the three theoretical bases of SQL?

A
  • Set theory
  • Relational algebra
  • Predicate calculus
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Define the relational model

A
  • Model that stores all its data in interconnected tables.
  • High level query language
  • Theoretical basis consisting of relational algebra and set theory
  • Basic construct is a TABLE (relation)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Define rows and columns in relational database design.

A

Rows: Tuple

Columns: Attributes

  • GPA would be an attribute NAME
  • 3.75 would be an attribute VALUE
  • Each attribute has a type, NULL being special
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What two values can there be for NULL in relational database design?

A

Unknown and undefined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

True or false: Someone with a NULL GPA would still be listed in the following queries: SELECT * FROM Students WHERE GPA Not 3.5 SELECT * FROM Students WHERE GPA > 3.5 SELECT * FROM Students WHERE GPA

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Define schema

A

Structural description of table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Define instance

A

Actual contents of table at that time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Does ordering of the tuples matter?

A

No, and that goes back to set theory. {1,2,3,4} = {2,4,3,1}

19
Q

Does ordering of the columns matter?

A

Yes, if attribute names are not specified. The following statement would not work without ordering of columns. INSERT INTO Students VALUES (‘Smith’, 17, 3.8, 1)

20
Q

True or false: Every tuple MUST be unique.

21
Q

Define a “Key”

A

A set of attributes whose value is unique in each tuple

22
Q

What are the different types of keys?

A

Primary key: Only one candidate key can become a primary key. Underlined in schema.

Candidate key: A set of attributes that qualify as a unique key in a database. Each one can qualify as a primary key.

23
Q

What are set members in relational database design?

A

All of the tuples in the table

24
Q

A union B

A

Everything in A, B, and the part that intersects A and B.

25
A intersect B
Only the part that intersects A and B.
26
Compliment of A
EVERYTHING outside of A (drawn with a box)
27
A - B
Everything in A that does not intersect with B.
28
A X B
{1,2,3} x {a,b} = {(1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c)}
29
What are the operators in relational algebra?
Union, intersect, cross, subtraction, select (sigma) and project (pi)
30
Relational algebra query to list employees from department number 4.
σ\_dno=4 (Employee)
31
Relational algebra query to list employees with salary \> 30000
σ\_salary\>30000 (Employee)
32
Relational algebra query to list employees from department 4 and salary \> 25000 or salary \< 40000
σ\_dno=4 ^ salary\>25000 v salary\<40000(Employee)
33
Relational algebra query to list employees fname, lname, and salary
π\_fname,lname,salary(Employee)
34
Explain how duplicates are handled in relational algebra versus SQL
Relational Algebra: Duplicates are NOT included in output SQL: Equivalent query WOULD contain duplicatesi in output
35
Relational algebra query to list last name and salary of employees in department 5.
π\_lname,salary(σ\_dno=5 (Employee))
36
Relational algebra query to list the last name and salary of employees in department 5 who earn \> 30000
π\_lname,salary(σ\_dno=5 ^ salary\>30000 (Employee))
37
Rename operator
ρ: Renames an output table. ρ\_firstName(π\_fname(EMPLOYEE))
38
When can you use the union, intersects, or subtraction operator on tables?
When the attributes in both tables have identical types: Same attribute domains (i.e. numbers, names, etc.)
39
Student: Adam, Jon, Mary Instructors: Adam, Dona Student union Instructors
Adam, Jon, Mary, Dona
40
Student: Adam, Jon, Mary Instructors: Adam, Dona Student intersects Instructors
Adam
41
Student: Adam, Jon, Mary Instructors: Adam, Dona Student - Instructors
Jon, Mary
42
Student: Adam, Jon, Mary Instructors: Adam, Dona Instructors - Student
Dona
43
Relational algebra query to list SSN of all employees who either work in department 5 or supervise an employee who works in department 5.
π\_ssn(σ\_dno=5(EMPLOYEE)) U π\_super\_ssn(σ\_dno=5(EMPLOYEE))