0% found this document useful (0 votes)
6 views2 pages

Primary Key Constraint

The document outlines various types of database constraints including primary, foreign, not null, unique, exclusion, and check constraints, which ensure data integrity and relationships between tables. It also provides SQL commands for creating tables, inserting, updating, and deleting data, as well as altering table structures and constraints. The information is essential for managing and manipulating relational databases effectively.

Uploaded by

Mace Chua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Primary Key Constraint

The document outlines various types of database constraints including primary, foreign, not null, unique, exclusion, and check constraints, which ensure data integrity and relationships between tables. It also provides SQL commands for creating tables, inserting, updating, and deleting data, as well as altering table structures and constraints. The information is essential for managing and manipulating relational databases effectively.

Uploaded by

Mace Chua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PRIMARY KEY CONSTRAINT– Column or group that is used to mainly identify a row by

containing unique and non-null data.


*Commonly the column that is used to JOIN tables together.

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

UNIQUE CONSTRAINT – Ensures that all data in a column is all unique

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;

REFERENCES – Used for referencing columns from other tables


CREATE TABLE table name(column name TYPE REFERENCES table name(column 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;

UPDATE JOIN TABLE – Updating the data of a table to be a duplicate/reference of a column


from another table
UPDATE table 1 SET original column = table 2.column name FROM table 2 WHERE table
1.common column = table 2.common column;

DELETE DATA
DELETE FROM table
WHERE column = value;

DELETE JOIN DATA


DELETE FROM table 1 USING table 2 WHERE table 1.common column = table 2.common
column;

ALTER COLUMN DATA


ADDING COLUMN
ALTER TABLE table ADD COLUMN new column TYPE

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;

You might also like