Running PostgreSQL
Docker
Docker Desktop
To start a (detached) Postgres Docker Container
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
To directly go into pqsl
docker run -it --rm postgres psql -h some-postgres -U postgres
Docker Compose
To run PostgreSQL using Docker Compose, create a file:
| |
AWS RDS
Database Connection
Database/Table Management
Creating/Deleting Databases
Create Database
CREATE DATABASE suppliers;
Delete Database
Creating/Deleting Tables
Create Table
| |
Delete Table
| |
CASCADE:RESTRICT:
Altering Tables
?
Data Types
Constraints
NOT NULL
ensures that values in a column cannot be NULL.
UNIQUE
ensures the values in a column unique across the rows within the same table.
PRIMARY KEY
a primary key column uniquely identify rows in a table. A table can have one and only one primary key. The primary key constraint allows you to define the primary key of a table.
CHECK
a CHECK constraint ensures the data must satisfy a boolean expression.
| |
FOREIGN KEY
ensures values in a column or a group of columns from a table exists in a column or group of columns in another table. Unlike the primary key, a table can have many foreign keys.
Querying
Select
Filtering
Joins
Inner Joins
| |
Left Join
| |