tables residing on diskviews — virtual tables resulting from computationtemporary tables — internally created, used, and thrown away; can’t be accessed by usersHere are some example SQL table creation commands
CREATE TABLE Movies (
title CHAR(100),
year INT,
length INT,
genre CHAR(10),
studioName CHAR(30),
producerC# INT
);
CREATE TABLE MovieStar (
name CHAR(30),
address VARCHAR(255),
gender CHAR(1),
birthdate DATE
);Mention case-(in)sensitivity of keywords & names here.
Deleting a relation:
DROP TABLE R;Adding a new attribute:
ALTER TABLE MovieStar ADD phone CHAR(16);Deleting an existing attribute:
ALTER TABLE MovieStar DROP birthdate;When creating a table, we can provide default values that’s different from NULL to attributes, e.g.
CREATE TABLE MovieStar (
name CHAR(30),
address VARCHAR(255),
gender CHAR(1) DEFAULT '?',
birthdate DATE DEFAULT DATE '0000-00-00'
);Can use default values at attribute modification time as well, e.g.,
ALTER TABLE MovieStar ADD phone CHAR(16) DEFAULT 'unlisted';Add one phrase right after the normal attribute declaration, like this
CREATE TABLE MovieStar (
name CHAR(30) PRIMARY KEY,
address VARCHAR(255),
gender CHAR(1),
birthdate DATE
);or like this
CREATE TABLE MovieStar (
name CHAR(30) UNIQUE,
address VARCHAR(255),
gender CHAR(1),
birthdate DATE
);UNIQUE means NULL value allowed while PRIMARY KEY means NULL value not allowed.
Declare the group of attributes to be key after declaring all attributes, like this
CREATE TABLE MovieStar (
name CHAR(30),
address VARCHAR(255),
gender CHAR(1),
birthdate DATE,
PRIMARY KEY (name)
);
CREATE TABLE Movies (
title CHAR(100),
year INT,
length INT,
genre CHAR(10),
studioName CHAR(30),
producerC# INT,
PRIMARY KEY (title, year)
);UNIQUE can be used in place of PRIMARY KEY with the same meaning described in last slide.