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
CREATE TABLE T1 ( PID INT PRIMARY KEY,score INT,ISMInorITY VARCHAR(1) );
  • Table T2
    we are going to define a fk constraint and a check constraint on T2
    • the inline way
CREATE TABLE T2 ( PID INT CONSTRAINT FK_PID REFERENCES T1(PID),ISMInorITY VARCHAR(1) CHECK(ISMInorITY IN ('N','Y')) );
  • the out-of-line way
CREATE TABLE T2 ( PID INT,ISMInorITY VARCHAR(1),CONSTRAINT FK_PID FOREIGN KEY (PID) REFERENCES T1(PID),CONSTRAINT CHECK_ISMInorITY CHECK(ISMInorITY IN ('N','Y')) );

相关文章

Java Oracle 结果集是Java语言中处理数据库查询结果的一种方...
Java AES和Oracle AES是现代加密技术中最常使用的两种AES加密...
Java是一种广泛应用的编程语言,具备可靠性、安全性、跨平台...
随着移动互联网的发展,抽奖活动成为了营销活动中不可或缺的...
Java和Oracle都是在计算机领域应用非常广泛的技术,他们经常...
Java 是一门非常流行的编程语言,它可以运行于各种操作系统上...