psql -U postgres -d intro_to_sql_problem_set < RELATIVE/PATH/TO/THIS/FILE/intro-to-sql-problemset.sql
where RELATIVE/PATH/TO/THIS/FILE/intro-to-sql-problemset.sql
is the relative path to the downloaded .sql file
We can read this whole command as
psql
: "Start the psql repl"-U postgres
: "As the user named postgres"-d intro_to_problem_set
: "automatically connect me to a database named intro_to_problem_set"<
: Put something into that databaseRELATIVE/PATH/TO... .sql
: Put into the database this specific file
Therefore, the last argument should be a path where your current terminal location can access that downloaded sql file!
syntax | meaning |
---|---|
\l |
list all available Postgres databases on this machine |
\c db_name |
connect to a database |
\dt |
(must be connected to a database first!!) view a list of all tables that are within the connected database |
CREATE DATABASE db_name;
DROP DATABASE db_name;
CREATE TABLE example_table_name (
column_name data_type constraint_name,
column_name data_type constraint_name
);
CREATE TABLE example_table_name (
column_name data_type PRIMARY KEY,
column_name data_type constraint_name
);
CREATE TABLE example_table_name (
column_name INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
column_name data_type constraint_name
);
DROP TABLE example_table_name;
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
SELECT column1, column2, column3, ... FROM table_name;
SELECT * FROM table_name;
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
DELETE FROM table_name
WHERE condition;