Database Reference
In-Depth Information
A table can have multiple parent tables, which means that we can
have more than one foreign key in a single table.
Check constraints
A check constraint lets you deine a condition that a column must fulill a Boolean
expression. Let's understand this with some examples:
warehouse_db=# CREATE TABLE tools
(
tool_id INTEGER PRIMARY KEY,
tool_name TEXT,
tool_class NUMERIC,
tool_quantity NUMERIC CHECK (tool_quantity > 0)
);
In the preceding query, we have created a table with check constraints on
tool_quantity to make sure that it must be greater than 0 .
You can also give your constraints a more user-friendly name, so see the following
example in which we name the constraint positive_quantity :
warehouse_db=# CREATE TABLE tools
(
tool_id INTEGER PRIMARY KEY,
tool_name TEXT,
tool_class NUMERIC,
tool_quantity NUMERIC
CONSTRAINT positive_quantity CHECK
(tool_quantity>0)
);
Privileges in PostgreSQL
In PostgreSQL, multiple privileges are present for every object that is created.
By default, the owner (or a superuser) of an object has all the privileges on it.
In PostgreSQL, the following types of privileges are present:
• SELECT
• INSERT
• UPDATE
 
Search WWH ::




Custom Search