Lecture 3 - SQL CREATE Flashcards
What type of language is SQL?
a declarative language -> we say what rather than how
Statement for creating a schema in SQL?
CREATE SCHEMA name;
Each statement ends with a what in SQL?
;
SQL statement for creating a table?
CREATE TABLE name (attrs)
What do we need to specify when creating a table in SQL?
the name of the relation
attributes and their domain
any constraints
What domains can we have in SQL?
integer
real / decimal(digits , sig figs after decimal)
char(n)
varchar(n)
bit
bit varying
bool
date
timestamp
date intervals
Difference between char and varchar
Char allows exactly n characters while varchar allows from 0 to n characters
How do we put a PK constraint into CREATE TABLE?
At the end PRIMARY KEY (attr)
How do we put a FK constraint into CREATE TABLE?
At the end FOREIGN KEY (attr) REFERENCES TABLE(attr(s))
What value constrains are possible in SQL?
- default value
- NOT NULL
- CHECK CLAUSE (checking if given value meets requirements and boundries)
What is the key constraint in SQL?
that the primary key is unique
What is an entity integrity constraint in SQL?
PK can’t be null
What is the UNIQUE clause?
specific candidate keys as they can uniquely identify a field
What are the triggered actions that are most common? (what happens on delete/update on relations with a referential constraint)
Action: ON DELETE SET NULL/ DEFAULT/ CASCADE
Action: ON UPDATE SET NULL/ DEFAULT /CASCADE
What is CASCADE?
propagate the change (DELETE/UPDATE) to referential relations