Database Reference
In-Depth Information
2.
Using the following command, you can log in to the default database
with the user
postgres
and you will be able to see the following on your
command line:
psql (9.4beta1)
Type "help" for help
postgres=#
3.
You can then create a new database called
warehouse_db
using the following
statement in the terminal:
postgres=# CREATE DATABASE warehouse_db;
4.
You can then connect with the
warehouse_db
database using the
following command:
postgres=# \c warehouse_db
5.
You are now connected to the
warehouse_db
database as the user
postgres
,
and you will have the following
warehouse_db
shell:
warehouse_db=#
Let's summarize what we have achieved so far. We are now able to connect with the
default database
postgres
and created a
warehouse_db
database successfully. It's
now time to actually write queries using
psql
and perform some
Data Deinition
Language
(
DDL
) and
Data Manipulation Language
(
DML
) operations, which we
will cover in the following sections.
In PostgreSQL, we can have multiple databases. Inside the databases, we can have
multiple extensions and schemas. Inside each schema, we can have database objects
such as tables, views, sequences, procedures, and functions.
We are irst going to create a schema named
record
and then we will create some
tables in this schema. To create a schema named
record
in the
warehouse_db
database, use the following statement:
warehouse_db=# CREATE SCHEMA record;
Creating, altering, and truncating a table
In this section, we will learn about creating a table, altering the table deinition,
and truncating the table.