Skip to content

Database cheatsheet for terminal

Sharina Stubbs edited this page May 12, 2020 · 3 revisions

Connect to database

$ \c database-name 

List all available databases

\l

Once in the DB, create a table:

CREATE TABLE Persons (
    PersonID int,
    LastName varchar(255),
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255)
);

See the columns within the table

\d table_name

To see all available psql commands

\?

To get help on a particular command, such as INSERT

\h insert

See database relations

$ \d 

See tables within the database

$ \dt

Quit psql

\q

Resources

https://www.postgresqltutorial.com/psql-commands/

Clone this wiki locally