Skip to main content

❓ How to create a database from the console?

Download Postgresql (Ubuntu):​

sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh

Enter postgres:​

sudo -u postgres psql

Create a Database:​

 CREATE DATABASE database_name;

Show the list of databases:​

\l

Create a table:​

CREATE TABLE table_name (attribute_name1 data_type1, attribute_name2 data_type2, ...);

select the database:​

\c database_name

Create the table:​

CREATE TABLE table_name (attribute_name1 data_type1, attribute_name2 data_type2, ...);

Show tables in the database:​

\dt

Show table structure:​

\d table_name

Insert data in the table:​

INSERT INTO table_name (attribute_name1, attribute_name2, ...) VALUES (value1, value2, ...);. 

Show the table:​

SELECT * FROM table_name;

Show the data from a specific attribute from the table:​

SELECT attribute_name2 FROM table_name;