| created on | January 8, 2022 |
creating a database and set the owner
postgres=# create database sampledb encoding 'UTF8' owner alice;
Encoding UTF-8 is almost always a sane choice.
dropping a database
postgres=# drop database sampledb;
creating and dropping a schema
drop schema if exists business_data cascade;
create schema business_data;
creating a sequence
create sequence business_data.user_id_seq start 1 increment 1 maxvalue 9999999999 minvalue 1 cache 1;
creating a table with a primary key from a sequence and a foreign key
create table business_data.user (
id integer default nextval('business_data.user_id_seq'::text),
first_name varchar(128) not null,
last_name varchar(128) not null,
title varchar(128),
...
zip varchar(128) not null,
city varchar(128) not null,
country integer not null,
t ax_identification_number varchar(128) not null,
constraint "user_pk" primary key ("id"),
constraint "user_fk_country" foreign key (country)
references base_data.country (id)
);