前端之家收集整理的这篇文章主要介绍了
Oracle 的constraint写法,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
- 前言
There are a couple of ways to add constraints to restrict the values in the database. This article is about how to define a foreign key constraint and a check constraint in two ways.
- Table T1
@H_404_10@CREATE @H_404_10@TABLE T1 ( PID @H_404_10@INT @H_404_10@PRIMARY @H_404_10@KEY,score @H_404_10@INT,ISMINORITY @H_404_10@VARCHAR(1) );
- Table T2
we are going to define a fk constraint and a check constraint on T2
@H_404_10@CREATE @H_404_10@TABLE T2 ( PID @H_404_10@INT @H_404_10@CONSTRAINT FK_PID @H_404_10@REFERENCES T1(PID),ISMINORITY @H_404_10@VARCHAR(1) @H_404_10@CHECK(ISMINORITY @H_404_10@IN ('N','Y')) );
@H_404_10@CREATE @H_404_10@TABLE T2 ( PID @H_404_10@INT,ISMINORITY @H_404_10@VARCHAR(1),@H_404_10@CONSTRAINT FK_PID @H_404_10@FOREIGN @H_404_10@KEY (PID) @H_404_10@REFERENCES T1(PID),@H_404_10@CONSTRAINT CHECK_ISMINORITY @H_404_10@CHECK(ISMINORITY @H_404_10@IN ('N','Y')) );