Day-1
Creating Databases and Tables in PostgreSQL
How to Create a Database in PostgreSQL
There are two common ways to create a PostgreSQL database:
- Using Terminal / psql [Linux]
- Using pgAdmin
Create a Database Using Terminal
sudo -i -u postgres
sudo (superUser Do) → run a command with administrator privileges
-i → start a login shell
-u → specify which user to switch to
postgres → PostgreSQL system user
CREATE DATABASE company;
we can check the version with the SQL statement ,
SELECT version();
note :
\l - to Check databases
\c company - to connect Database
\d - It shows the tables, views, sequences, etc.
in the current database
In pgAdmin4
PostgreSQL Create Table
CREATE TABLE employee(
id INT,
name VARCHAR(25),
role VARCHAR(25),
exp INT
);
PostgreSQL Insert Data
- Insert one row
INSERT INTO employee (id, name, role, experience)
VALUES (1, 'vidhya', 'Full Stack Developer', 1);
- Insert multiple rows
INSERT INTO employee (id, name, role, experience)
VALUES
(1, 'Vidhya', 'Developer', 2),
(2, 'Arav', 'Tester', 3),
(3, 'Amutha', 'Manager', 5),
(4, 'Prem', 'Developer', 4);
Display Table
To check the result we can display the table with this SQL statement:
SELECT * FROM employee;
That's it for Day 1. To be continued.....



Top comments (0)