2. Introduction to SQL Flashcards
Features
Data Manipulation Language:
-Query data
-Insert/modify / remove data
Data Definition Language :
-Create/ Modify tables
-Define triggers
-Create constraints
What are the main data manipulation tasks?
Requesting data
Inserting data
Deleting data
Changing data
What are the main data definition tasks?
Create tables
Deleting tables
Changing tables
What does it mean for SQL to be strongly types?
Error if you use the wrong data types
What does it mean for SQL to be statically typed?
You cannot modify the type mid program
What are the main data types in SQL?
Boolean - T/F
Integer - integers
Decimal - exact fixed point number
Double - 64 bit floating point numbers
Date - date
DATETIME - a date plus time
CHAR(n) - fixed length character string
VARCHAR(n) - variable length character string
TEXT - string of text
BLOB - binary storage
What database design feature does strong typing help solve?
Data integrity –> overall accuracy and consistency of data
Restriction
Condition: boolean expression for which rows to include
Made of :
- Column names from referenced tables
- Literals : numbers, strings….
- Operators: =, <> , >, >=, <, <=
- Combining terms: AND, OR
- Missing values: IS NULL, IS NOT NULL
- Within a subquery: IN, NOT IN
Ordering Output
ORDER BY
Cross Join (Cartesian product)
Produces all possible combinations of the rows of 2 tables (does not care if there are crossovers that are false)
DO NOT USE THS
Inner Join (Natural Join)
Keeps only rows with matching common columns
Eliminates rows from both tables that do not satisfy the join condition –> gives us the INTERSECTION of two tables ( think stats)
Most common join
Outer Join
Returns matched values and unmatched values from either or both tables
3 Types:
1) LEFT JOIN: returns only unmatched rows from the left table, as well as matched rows in both tables
2) RIGHT JOIN: returns only unmatched rows from the right table, as well as matched rows in both tables
3) FULL OUTER JOIN: returns unmatched rows from both tables, as well as matched rows in both tables
THINK OF THE JOINS IN TERMS OF PROBABILITY CONCEPTS
Aliasing tables
Tool for abbreviating reference to table name –> useful for referring to commonly used tables
Syntax:
<table> AS <alias>
EX:
Select d.dname, e.salary
FROM Department AS d, EMPLOYEE as e
WHERE d.id = e.id
</alias></table>