Saturday 18 May 2019

Postgres: Create database

Create a database

Execute below command to create database.

createdb -U postgres -h localhost {databaseName}

 

Example

createdb -U postgres -h localhost myOrg

 

Once the database is created, you can login to the database by executing the command ‘psql --dbname=myOrg’.

$createdb -U postgres -h localhost myOrg
Password:

Login to myOrg database

psql -U postgres -h localhost --dbname=myOrg


$psql -U postgres -h localhost --dbname=myOrg
Password for user postgres: 
psql (14.4)
Type "help" for help.

myOrg=#

Create employee table and query

myOrg=# CREATE TABLE employee (id INT, name VARCHAR(20));
CREATE TABLE
myOrg=# 
myOrg=# SELECT * FROM employee;
 id | name 
----+------
(0 rows)


Previous                                                 Next                                                 Home

No comments:

Post a Comment