Postgres ( Basic Introduction )

Password abcd1234 and user is postgres, port 5432


Create Database -

createdb mydb   # it may not work

createdb mydb -U postgres mydb 


Drop Database -

dropdb -U postgres mydb


Connect to DB from command line -

createdb mydb -U postgres mydb 

psql.exe -U postgres mydb


Basic commands -

mydb=# select version();


Adding users 

postgres=# create database mydb;

postgres=# create user myuser with encrypted password 'mypass';

postgres=# grant all privileges on database mydb to myuser;


List of Databases -

\l will display the list of the databases;

postgres=# \l

Connect to a DB

postgres=# \c mydb;


List of Relations(tables) - 

testamar=# \d



Create Table 

CREATE TABLE COMPANY(
   ID INT PRIMARY KEY     NOT NULL,
   NAME           TEXT NOT NULL,
   AGE            INT NOT NULL,
   ADDRESS        CHAR(50),
   SALARY         REAL
);



         

Row Insertions -

INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, 'Paul', 32, 'California', 20000.00);

Display contents from the Table -

select * from company;