Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
103 Cards in this Set
- Front
- Back
What is a Database Management system? |
System software for creating and managing a database that provides: |
|
What does a Database Management System manage? (3) |
1. Data 2. Database Engine 3. Database schema provide concurrency, data integrity and uniform administrative procedures |
|
Why are DBs important? |
It's difficult. A lot of research has gone into doing it the right way. Learn how to deal with "big data" in real-time. i.e. create salable reliable systems |
|
What makes a database a database? |
Accessibility and concurrent access Put a lot of info in as little space (no duplicates) Data integrity. Modification is done across all instances. Security. |
|
Why do we need DBMS'? (4) |
1. Redundancy 2. File Formats 3. Data Access 4. Physical Data Indpendence |
|
Redundancy |
A flat file has no optimization so that data doesn't appear more than once. Databases optimize to reduce redundancy/duplicates to make queries run faster Relational model - put as much data in as small a space as possible |
|
Multiple files, duplicate info |
You can either: |
|
Accessing Data from multiple applications |
Databases mean you don't have to rewrite new implementation each time a program needs access to the data. Standardization with SQL. |
|
Data Isolation |
Databases allow you to put locks on certain types of data or prevent data from being modified until certain conditions are met. This way data is kept safe and secure from rogue code or malicious input. |
|
Data integrity |
Databases maintain the data in a consistent and accurate way so that it isn't corrupted (through a variety of means) |
|
Atomicity of updates |
Databases ensure that updates are applied to all elements of affected data in a binary way. Either the transaction happens completely or not at all. There is no "in progress" which maintains the state of the database. i.e. bank balance transfers. Either the money is moved from one account to another or it is not. There is no partial transfer and then failure. |
|
Concurrent Access |
Multiple users can access at the same time and it appears as if the database is only being used by one user. Also ensures data integrity when one piece of data is accessed by the multiple users at once. |
|
Data Abstraction |
Databases provide levels of abstraction so that you don't have to manipulate the data on the lowest level. Provides usability. Phsyical: Logical: View |
|
Physical Data Indpendence |
As an application writer you don't want to deal with how the data is actually physically stored. Instead, we work with a MODEL of the data not the data itself. The DB abstracts away stuff we don't want to think about. Allows us to switch implementations of code and leave the SQL or Database section intact |
|
Schema vs. Instance |
A schema is the logical design/description of the data. An instance is a snapshot of the data stored in a DB at any given time. Class vs. object in Java |
|
Why modeling your DB what should you think about? |
The level of detail accuracy you need. Don't want it too detailed or else it becomes bloated/excessive but it also needs to represent the real world accurately. |
|
What is a relation? |
A relation deals with tuples and attributes within a table (which holds rows & columns) Think of the relation as individual data within a table (schema vs. instance) |
|
Super key vs. Candidate key vs. Primary key |
Super key - any attributes that can uniquely identify a tuple |
|
What makes a good primary key? |
1. Doesn't change 2. Unique 3. Non-null such that everyone has that attribute |
|
Relation vs. table |
Relation are the rows in the table while the table is just the schema identifying what it looks like or how the data should be laid out. Table: - Has an order, is a list, can have duplicates Relation: - No order, no duplicates, is a SET |
|
DDL vs. DML |
Data Definition Language Data Manipulation Language Both part of the SQL language; One sets up the schema (DDL) through things like CREATE and ALTER while DML effects the instance of the table with SELECT, INSERT, UPDATE, DELETE or whatever |
|
Do Sailors and Bank RA examples |
Do Sailors and Bank examples |
|
Select (RA) |
sigma (o-)p(r) where p is the predicate and r is the relation (table) Predicates can compare to a value or to another attribute Limits the specific tuples or rows from a relation or table SELECT in SQL is Project in RA |
|
Projection (RA) |
pi..a1,a2,..an where A is an attribute returns the attributes (columns) from a relation duplicates are removed |
|
Rename (RA) |
rho - (p) (p)x(E) renames the result of expression E to x while (p)x(a1..a2..a3..etc.)(E) renames the attributes of that expression to a1,a2,a3, etc. |
|
Union (RA) |
U - combine tuples from two relations. r U s: 1. r and s must have same degree (num attributes) 2. The corresponding domains must have a compatible type Keyword: "or" in English |
|
Intersect (RA) |
r (-) s where r and s are two relations: combine tuples that are present in both relations; same rule as union Keyword: "and" in English |
|
Set Difference (RA) |
- r-s, where r and s are two relations Find tuples that are in one relation but NOT in another 1. r and s must have same degree 2. Corresponding attribute domains must have a compatible type Keyword: "are not" |
|
Cartesian (Cross) Product (RA) |
(x) r x s where r and s are relations The attributes of the 1st relation followed by the attributes of the 2nd for all of the attributes of the 1st relation NOT commutative |
|
Natural Join (Inner Join) (RA) |
Combines a selection and a cross product 1. Cross products 2. Selects forcing equality on those attributes that appear in both relation schemas 3. Removes duplicates Keep all tuples that have the same value for the shared attributes |
|
Natural Join - Flo's method |
Cross product, if the columns shared by both tables match, add that row to the new one with non matching columns. |
|
Outer join |
Takes all tuples in the left relation that did not match with any tuples in the right relations, pads tuples with null values for all other attributes and adds them to the result of the natural join |
|
Outer join - Flo's interpretation |
Same as Natural Join just fills the non matching/present columns with nulls if the overlapping attribute does not match |
|
Aggregate Functions (RA) |
G1,G2,..Gm (G) F1(A1),F2(A2),...Fn(An) (R) G are the attributes on which to group F is the aggregate function on attribute R is relation Keyword: "of each" |
|
Group By |
Groups by some attribute and then applies all of the aggregate functions to that group |
|
Division (RA) |
r (division symbol) s where s is a subset of r Find A for all B where A and B are attributes All A's paired with their Bs / all possible B's Result: List of A's Keyword: "For all" |
|
Division - Flo's take |
Opposite of cross product. If attribute from A do not have all possible B matches (as from cross product) then it is NOT added. If A has all possible B's then it IS added. |
|
What are ER diagrams? |
Used to design a database. Consists of entites and relationships between them (Entity-Relationship Diagram) |
|
Entity? |
Any object that is distinguishable from any other - Have attributes - Entity set is a set of entites of the same type - Value domain: set of permitted values for each attribute - Simple or composite: composite has multiple attributes stemming out of - Single or multiple values: multiple phone numbers per person - derived - null or not null |
|
Relationship? |
An association between 2 or more entities Think: participation and cardinality Can have their own attributes represented by dashed line. |
|
Participation |
How many entities in the set are involved in the relationship? Total - double edge - every entity in the entity set participates in the relationship Partial - single edge - not every entity in the entity set required to participate |
|
Cardinality |
How are the entity sets involved together? 1-to-1: one entity from set A with one entity from set B. Represented by arrow both directions. 1-to-many: one entity from set A with many entities from set B. Arrow points to single side. many-to-many: many entities from set A associated with many entities from set B. Cardinality says NOTHING about participation. Can be ZERO. |
|
Recursive (self-referential) relationships |
An entity set can relate to itself in a self relating relationship. The relationship from and back need to be labeled and they are called "roles." Primary keys renamed as roles. |
|
Entity sets in ER Diagrams |
Rectangle |
|
Relationship sets in ER Diagrams |
Diamonds w/attributes stemming off |
|
Cardinality in ER Diagrams |
Number of lines (single or double) |
|
Ellipses in ER Diagrams |
Attributes (single value) |
|
Double Ellipses in ER Diagrams |
Multi-valued attributes |
|
Dashed Elipses in ER Diagrams |
Derived attribute |
|
Arrow in ER Diagrams |
"one" relationship (cardinality) |
|
Undirected arrow in ER Diagrams |
"many" relationship |
|
What makes a good entity set? |
Set of entities within it that share the same type and the same properties |
|
What makes a good relationship? |
Is there an association between them and is it meaningful? |
|
When should it be an entity or attribute? |
If you need more info about it, make it an entity set. If it is the info, make it the attribute. |
|
Binary vs. n-ary Relationship sets |
How many entity sets are participating in this relationship? Binary is two, anything more is n-ary |
|
Weak entity set? |
Not enough info contained within it to uniquely identify it. Requires a strong entity set's primary key(s) and a discriminator to be identified. Primary key: primary key of A's and discriminator. Represented by double rectangle and double diamond (relationship). Only the double rectangle represented as table in DB. MUST be total participation. |
|
Reducing ER Schema to tables |
Primary keys allow entity sets & relationships to be expressed uniformly as tables. Database conforming to ER can be represented as a collection of tables. Each entity set and relationship gets to be a table. |
|
Strong entity set to Table |
table_name(primary_key (underlined), other_attributes) |
|
Strong entity set with Composite Attribute to Table |
Composite attributes take on the composite first underdash higher attribute i.e. name becomes first_name, middle_name, last_name. within the table definition. |
|
Strong entity set with multivalued attribute to Table |
Attribute M on an entity set E is represented by a separate table named E_M (phone in instructor becomes instructor_phone) EM table has primary key of E and attributes of multivalued. ALL ARE PRIMARY KEYS. |
|
Many to Many relationship set to Table |
Primary keys of the two entity sets and any attributes on the relationship itself along with attribute of the relationship itself (dotted line to). |
|
One to many/many to one to Table |
IF total participation on the many side. Primary key comes from the many side with added extra attribute the primary key of the one side. Must be many because the one side has a lot associated with it so it doesn't discriminate. |
|
One to one to Table |
Either side can take the primary of the other; whichever makes more sense. |
|
Can you specify limits on cardinality? |
NOT in the DB. This is done programmatically instead. |
|
Weak entity set to Table |
All primary keys of the identifying strong entity set plus the discriminator (as primary key) and any other attributes. |
|
ISA (to table) |
Points to the specialization Primary key of superclass is the primary key and then extra attributes. Each represented as a sepreate table. |
|
Derived attributes (in tables) |
Derived attributes are not represented in the table itself (since they are derived) |
|
See bank-enterprises pdf |
See bank-enterprises pdf |
|
RA vs. SQL functionality |
RA was for query and manipulation SQL does table/schema definition, query and modification, transaction control, embedded SQL, integrity contstraints, authorization |
|
SELECT in SQL vs. in RA |
SELECT FROM is the same as Project |
|
WHERE in SQL vs. in RA |
Where is project and select |
|
Aggregate functions in SQL |
Use Group by to specify the column_name and perform the actual function in the SELECT HAVING restricts what is returned by the aggregate function (places a condition on it) |
|
Review SQL (text & cheat sheets) |
Review SQL (text & cheat sheets) |
|
Views |
temporary table created for running queires on. Usually only necessary to save typing time/etc. |
|
Data Types |
Simplest way to control what kind of data is in your database. Forces all data populating an attribute to look a certain way. |
|
Integrity Constraints |
Makes sure data in your DB is valid. Foreign keys make sure the data exists in another table before putting into yours. NULL or not. Refuse to let something be entered into DB without a value. Primary key, default values |
|
Checks |
A truth statement that you make about a single field in one table that is checked any time there is an insert or an update on that table. Update not allowed if check fails. Most are numeric. Incurs time cost. |
|
Assertion |
An assertion checks one table and multiple attributes that oculd involve a second table. "The sum in another table must be greater than the min in this table. More complex and powerful |
|
Triggers |
Event driven, react to updates, deletes or insertions. Once this event is detected they "do something" like perform a query. This is where building in business logic comes in handy. |
|
Problem with Advanced SQL business logic? |
Incurs more overhead as you get more complicated! |
|
Read heavy vs. write heavy database |
Be careful how many triggers used in write-heavy database as it will drastically negatively affect performance. |
|
Stored Procedures |
A function call. A stored procedure is a stored select or insert that you can pass parameters to. |
|
SQL data types (basic) |
char varchar int smallint numeric real, double float |
|
Basic Schema Definition |
CREATE TABLE r ( A1 D1, A2 D2, ...., An Dn, (integrity constraint), .... ); |
|
Basic Schema Definition Example |
CREATE TABLE course (course_id varchar(70) dept_name varchar(50) NOT NULL PRIMARY KEY (course_id) FOREIGN KEY (dept_name) references department); |
|
Typical SQL query form |
SELECT attribute1, attribute2, attribute(n) FROM r1,r2,r3 WHERE P; attributes are column names relations are tables P is a predicate condition for the select statement |
|
Renaming in SQL |
Use "as" |
|
Pattern matching on strings in SQL |
use LIKE operator % indicates it can match any substring _ matches character |
|
Sorting in SQL |
Use ORDER BY attribute followed by ASC or DESC depending on which you want |
|
Union and intersect operations |
Same as RA just with wrapping SELECT clauses |
|
How to find all but in SQL? |
Use the except operation |
|
Null values in boolean |
and - defaults to unknown unless false in which case it's false or - defaults to unknown unless true in which case it is true (this makes sense think of how or and and works) not - not unknown is unknown |
|
Basic aggregation in SQL |
perform it in the SELECT line |
|
Group By in SQL |
GROUP BY placed at the end with corresponding SELECT from beginning. Groups all of those matching that SELECT and then performs the aggregate function upon them |
|
Having in SQL |
Way to drop Grouped by rows that do not match the predicate/condition specfied by having. |
|
How to check if result is in a set in SQL? |
Use the "in" or "not in " keywords |
|
How to test if a result is greater than at least one or all of another set? |
Use the >= some or the >= all for every one |
|
Test for empty relations? |
Use "exists" |
|
"with" clause in SQL? |
with allows you to define a temporary relationship |
|
Deleting in SQL |
DELETE FROM r WHERE P; Where r is a relation(table) and P is a predicate. |
|
Insertion in SQL (single) |
INSERT INTO r VALUES(values defined by table, add null if need be) OR INSERT INTO r (attributes named) VALUES (corresponding attributes, rest will fill with NULL) |
|
Insertion in SQL (multiple) |
INSERT INTO r SELECT attributes/constants FROM r WHERE P; Same order but must specify if coming from SELECT or if constant. |
|
Updates in SQL |
UPDATE r SET attribute to whatever WHERE P; |