使用域,约束将成为域约束:
DROP DOMAIN PAYTYPE CASCADE;
CREATE DOMAIN PAYTYPE AS INTEGER
CHECK (value >= 1 AND value <= 666)
;
DROP DOMAIN ESTATUS CASCADE;
CREATE DOMAIN ESTATUS AS INTEGER
CHECK (value >= 1 AND value <= 2)
;
DROP TABLE MonthlyPayment CASCADE;
CREATE TABLE MonthlyPayment
( EmpID INTEGER NOT NULL PRIMARY KEY
, PaymentType PAYTYPE NOT NULL
, swiftcode varchar
);
DROP TABLE EmpAssignment CASCADE;
CREATE TABLE EmpAssignment
( EmpID INTEGER NOT NULL PRIMARY KEY
, status ESTATUS NOT NULL
);
现在测试它:
INSERT INTO EmpAssignment(EmpID,status) VALUES(1,9);
结果(使用 Postgresql-9.1):
ERROR: value for domain estatus violates check constraint "estatus_check"