个性化阅读
专注于IT技术分析

如何在Oracle中检查约束?

本文概述

在Oracle中, 检查约束对表的每一行都有特定的条件。

使用CREATE TABLE语句

句法

CREATE TABLE table_name
(
  column1 datatype null/not null, column2 datatype null/not null, ?
  CONSTRAINT constraint_name CHECK (column_name condition) [DISABLE]
);

例子1

CREATE TABLE student (id numeric(4), name varchar2(50), CONSTRAINT check_id CHECK(id  BETWEEN 1 and 10))
如何在Oracle中检查约束?

注意:在创建表的过程中, 我们应用了一个约束, 其中只能插入1至10行。因此, 在下面的查询中插入了12个字段。如果将生成错误消息。

INSERT ALL
  INTO student(id, name) VALUES (1, 'shristee')
  INTO student(id, name) VALUES (2, 'heena')
  INTO student(id, name) VALUES (3, 'mohit')
  INTO student(id, name) VALUES (4, 'shashank')
  INTO student(id, name) VALUES (5, 'avinash')
  INTO student(id, name) VALUES (6, 'shweta')
  INTO student(id, name) VALUES (7, 'suman')
  INTO student(id, name) VALUES (8, 'rohan')
  INTO student(id, name) VALUES (9, 'ali')
  INTO student(id, name) VALUES (10, 'dolly')
  INTO student(id, name) VALUES (11, ?mona?)
  INTO student(id, name) VALUES (12, 'kiran')
  SELECT * FROM dual;
如何在Oracle中检查约束?
INSERT ALL
  INTO student(id, name) VALUES (1, 'shristee')
  INTO student(id, name) VALUES (2, 'heena')
  INTO student(id, name) VALUES (3, 'mohit')
  INTO student(id, name) VALUES (4, 'shashank')
  INTO student(id, name) VALUES (5, 'avinash')
  INTO student(id, name) VALUES (6, 'shweta')
  INTO student(id, name) VALUES (7, 'suman')
  INTO student(id, name) VALUES (8, 'rohan')
  INTO student(id, name) VALUES (9, 'ali')
  INTO student(id, name) VALUES (10, 'dolly')
  SELECT * FROM dual;
如何在Oracle中检查约束?
赞(0)
未经允许不得转载:srcmini » 如何在Oracle中检查约束?

评论 抢沙发

评论前必须登录!