Primary Key Constraint
Primary Key Constraint
FOREIGN KEY CONSTRAINT– Data that were obtained from other tables that are considered
a primary key in their designated table.
*Commonly the column that is used to JOIN tables together.
*Primary and Foreign keys can be seen under the “Constraint” tab under schemas,
connections can be seen in “Dependencies”.
NOT NULL CONSTRAINT – Ensures that no value in a data under the column has a null value
EXCLUSION CONSTRAINT – Ensures that any two rows are compared on the specified
column or expression using the specified operator, not all of these comparisons will return
true
CREATING TABLE
CREATE TABLE table name(column name TYPE column constraint, column name TYPE
column constraint, table constraints) INHERITS existing table name;
INSERTING DATA
INSERT INTO table name(columns 1, column 2, column 3, column 4)
VALUES (data 1, data 2, data 3, data 4)
UPDATE TABLE
UPDATE table name SET column name = new data WHERE column name constraint;
DELETE DATA
DELETE FROM table
WHERE column = value;
REMOVING COLUMN
ALTER TABLE table DROP COLUMN column
RENAMING TABLE
ALTER TABLE table RENAME TO new name
RENAMING COLUMN
ALTER TABLE table RENAME COLUMN column TO new name
ALTER CONSTRAINTS
ALTER TABLE table ALTER COLUMN column
SET DEFAULT value
DROP DEFAULT
SET NOT NULL
DROP NOT NULL
ADD CONSTRAINT constraint
REMOVING DEPENDENCIES
ALTER TABLE table DROP COLUMN IF EXISTS column CASCADE
CHECK CONSTRAINTS - Ensures that all values in a column satisfies a certain condition
CREATE TABLE table name
(column name TYPE column constraint,
column name TYPE CHECK(column > value) column constraint,
table constraints)
INHERITS existing table name;