Week 2: Data Extraction Flashcards
REVERSED
- Physical level: describes how a record is stored
- Logical level: describes what data stored in the database and the relationships among the data e.g. name: string, salary: real
- View level: application programs which hide details of data types. Views can also hide information for security/privacy purposes
What are the 3 database levels of abstraction?
REVERSED
-structures: e.g. rows and columns, nodes and edges, key-value pairs
-constraints: e.g. all rows must have same number of columns, age must be positive, c
* operations: e.g. return the values of record x, find rows where the column “name” is “Jordan”
What are the 3 main components of data models?
REVERSED
- Schema: specifies name of relation, plus name and type of each column
- Instance: a table with rows and columns. rows = records = tuples, column = attributes = fields = features (instance is a snapshot of the schema at a point in time)
What are the 2 parts that a relation is made up of?
REVERSED
The number of columns
What is the degree of a relation?
REVERSED
The number of columns
What is the arity of a relation?
REVERSED
The number of rows
What is the cardinality of a relation?
REVERSED
attribute values are normally required to be atomic: indivisible (not containing more than one value)
What is the requirement of attribute values in a relation?
REVERSED
K is a superkey of R if values for K are sufficient to identify a unique tuple of each possible relation
What is a superkey of R?
REVERSED
Superkey K is a candidate key if K is minimal
What is a candidate key of R?
REVERSED
A selected candidate key used to represent the relation
What is the primary key of R?
REVERSED
column or set of columns in table whose values correspond to the primary key in another table
What is a foreign key of R?
REVERSED
- used for defining the database schema
- DDL is used to create and modify database objects such as tables, indexes and users
What is data definition language?
REVERSED
Language for accessing and manipulating the data in a model
DML is used for adding, deleting and modifying the records in a database
What is data manipulation language?
REVERSED
a statement requesting the retrieval of information
What is a query?
REVERSED
- and (^): retrieves records that satisfy both conditions
- or (v): retrieves records that satisfy one of the conditions
- not (~): retrieves records that don’t satisfy the condition
What are the three boolean operators?
REVERSED
A^F = F AvF = A A^T = A AvT = T
What are the 4 boolean laws including true and false
REVERSED
A^A = A AvA = A
What is A^A and AvA?
REVERSED
Av ~A = T
A^ ~A = F
What are the complement laws?
REVERSED
~(~A) = A
What is the double negation law?
REVERSED
~(A^B) = ~A v ~B ~(AvB) = ~A ^ ~B
What are de morgans laws?
REVERSED
A ^ (BvC) = (A^B) v (A^C) A v (B^C) = (AvB) ^ (AvC)
What are the distributive laws?
REVERSED
A v (A^B) = A A ^ (AvB) = A
What are the absorptive laws?
REVERSED
- the output of a relational algebra (RA) is a relation that can be input for another RA operator
- don’t need heaps of functions for each line of code
What are the advantages of composing relational algebra operators?
REVERSED
Union (U): total set of records in both relations, only records each record once even if it is in both
intersection: common records
difference (-): records in one table but not the other
selection (sigma): a specific set of rows
projection (pi): a specific set of columns. Duplicate tuples are removed
join: the natural join of two tables
What are the 6 main relational algebra operators?
REVERSED
rho (p)
What is the relational algebra symbol for renaming?
REVERSED
G or gamma
What is the relational algebra symbol for grouping and aggregation?
REVERSED
Gets all the tuples from relation R and pair them with all the tuples from relation S, end up with huge table
What does a cartesian product do?
REVERSED
set of all combinations of tuples in R and S that are equal on their common attribute names. and includes all other attributes from both relations filled in
What does a natural join do?
REVERSED
Pi(A1, sum(A3)) (A1, A2 G sum(A3) (sigma P (r1, r2)))
What is the form of relational algebra statement for the general sql query:
select A1, sum (A3)
from r1, r2
where P
group by A1, A2
REVERSED
Can do the union, intersection or set difference (-) of full relational algebra statements - but not include them within the statements
How do you use union, intersection and set difference in relational algebra?
REVERSED
- char(n) or character(n): character string with fixed length n
- varchar(n): variable length character string
- int or integer: integer of any length
- numeric(p,d): fixed point number with p digits and d of the digits are to the right of the decimal
- float(n): floating point number with precision at least n digits
What are the 5 basic types in SQL?
REVERSED
SELECT desired attributes
FROM one or more tables
WHERE condition about tuples of the tables
What is the basic form of a select from where statement?
REVERSED
SELECT DISTINCT
How do you force the elimination of duplicates in an SQL query?
REVERSED
SELECT *
How do you select all attributes in an SQL query?
REVERSED
results in a relation with one column and one row with value ‘542’
What is the result of SELECT ‘542’
REVERSED
returns a relation with one column and N rows(the number of tuples in instructor) where each row will contain the value ‘A’
What is the result of SELECT ‘A’ FROM instructor
REVERSED
using “as”
e.g. SELECT ID, name, salary/12.0 as monthly_salary
FROM instructor
or simply write salary/12.0 monthly_salary
do not need the “as”
How do you rename an attribute in SQL? (2 ways)
REVERSED
SELECT ID, name
FROM student
WHERE dept_name = ‘Math’ AND tot_cred >= 24
can also use OR
What do you use in the where clause to meet more than one criteria?
REVERSED
generates every possible instructor - teaches pair, with all attributes from both relations/ common attributes in the resulting table are renamed using the relation name
cartesian product
What is the result of
SELECT *
FROM instructor, teaches