SQL Flashcards
What is a static type system?
You declare a column with a specific data type
What is a dynamic type system?
Value stored in column determines its data type
Give examples of static type systems:
- MySQL
- PostgreSQL
Give examples of dynamic type systems:
- SQLite
What are data types in SQLite?
5 primitive data types:
NULL
INTEGER
REAL
TEXT
BLOB
What is the syntax for a creating a table?
CREATE TABLE tableName(
name type constraint
)
What is the syntax for linking foreign keys in tables?
Foreign key(foreignKey) REFERENCES tableName(candidateKey)
ON UPDATE action
ON DELETE action
What are some actions we can have for foreign key instances?
SET NULL
CASCADE
RESTRICT
SET DEFAULT
What are aggregate functions?
Act on a single column and returns a single value (used in select)
Give examples of aggregate functions
COUNT
SUM
AVG
MIN
MAX
What are the different types of joining?
Cross join
Inner join
Left join
What is cross join?
Computes the cartesian product of relations
What is inner join?
Matches each from from 1st relation with every row from 2nd relation over a common attribute
What is left join?
Matches each row from the first row with every row from the 2nd over a common attribute. If no common attribute, then NULL