PostgreSQL/Constraints/Constraints Basics
Версия от 13:45, 26 мая 2010; (обсуждение)
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=#