A database is a place where you can store, manipulate and retrieve data
- Flat file (like excel sheet)
- documents model databases (NOSQL)
- These databases content documents instead of tables
- Relational Databases - This is when 2 or more tables have a relationship between them
- Oracle Database (we need a license)
- MYSQL (own by oracle)
- SQL Server (own by Microsoft)
- PostgreSQL (free and open source)
It is a the language for talking to relational databases. It is used to create tables, insert data, retrieve data and much more.
PostgreSQL: The World's Most Advanced Open Source Relational Database ---> Download
- Default user: postgre
- Default port: 5432
Open postgreSQL through command prompt in windows PC
Search for env and edit it
C:\Program Files\PostgreSQL\13\bin
psql -U [username] -h [hostname]
psql -U postgres -h localhost
postgres pasword = 12345 master= Vanessa50======
ctrl +
ctrl -
\l
\q
\dt
\du
\! cls
\c [database name]
\c sales
CREATE DATABASE [database name];
CREATE DATABASE sales;
NB: only the supper user and the owner can drop the database
DROP DATABASE IF EXISTS [database name];
DROP DATABASE IF EXISTS sales;
DROP USER [user name];
DROP USER tia;
DROP TABLE [table name];
DROP TABLE accounts;
ALTER TABLE table_name
DROP COLUMN column_name;
ALTER TABLE accounts
DROP COLUMN user_email;
CREATE DATABASE yourdbname;
CREATE USER youruser WITH ENCRYPTED PASSWORD 'yourpass';
GRANT ALL PRIVILEGES ON DATABASE yourdbname TO youruser;
CREATE DATABASE hr;
CREATE USER john WITH ENCRYPTED PASSWORD '12345';
GRANT ALL PRIVILEGES ON DATABASE hr TO john;
CREATE ROLE paul WITH LOGIN PASSWORD '12345';
CREATE DATABASE master WITH OWNER paul;
\c master;
psql -U postgres -h localhost
psql -h localhost -p 5432 -U paul master
psql -h localhost -p 5432 -U john hr
psql -h localhost -p 5432 -U adam learning
psql -U postgres -h localhost
psql -h localhost -p 5432 -U adam learning
psql -h localhost -p 5432 -U tia learning
SELECT * FROM [table name];
SELECT * FROM locations;
--- Using pgAdmin - View table structure, and create column
OR
/*
Using pgAdmin - Rename, delete and change the data type of a column
Using pgAdmin - View table structure, and create column
*/