PostgreSQL/Constraints/Constraints Basics

Материал из SQL эксперт
Перейти к: навигация, поиск

Null column

postgres=# CREATE TABLE products (
postgres(#    product_no integer NULL,
postgres(#    name text NULL,
postgres(#    price numeric NULL
postgres(# );
CREATE TABLE
postgres=# drop table products;
DROP TABLE
postgres=#
postgres=#



Specifying range check in table creation

postgres=#
postgres=#
postgres=# CREATE TABLE products (
postgres(#    product_no integer,
postgres(#    name text,
postgres(#    price numeric CHECK (price > 0)
postgres(# );
CREATE TABLE
postgres=#
postgres=#
postgres=# drop table products;
DROP TABLE
postgres=#



Specifying two constaint for a single table

postgres=#
postgres=#
postgres=# CREATE TABLE products (
postgres(#    product_no integer NOT NULL,
postgres(#    name text NOT NULL,
postgres(#    price numeric NOT NULL CHECK (price > 0)
postgres(# );
CREATE TABLE
postgres=#
postgres=# drop table products;
DROP TABLE
postgres=#