A not-null constraint
makes sure that a column must have some values and a value is not left as null. Drop the previously created tools table and create the tools table again using this constraint using the following example:
warehouse_db=# CREATE TABLE tools
(
tool_id INTEGER NOT NULL,
tool_name TEXT,
tool_class NUMERIC
);
The preceding query will create a table with a not-null constraint on the tool_id column. We can apply the not-null constraint on as many columns as we can. Consider the following example:
warehouse_db=# CREATE TABLE tools
(
tool_id INTEGER NOT NULL,
tool_name TEXT NOT NULL,
tool_class NUMERIC
);
The preceding query will create the tools table with not-null constraints on tool_id and tool_name.
In the next article, we'll discuss Exclusion constraints
in postgresql.
Top comments (0)