Use check in Oracle for restrictions

Source: Internet
Author: User

Oracle provides a very useful clause check, which can automatically check data. It is used to create a table structure. For example:

Create Table worker
(Empno number (4) primary key,
Name varchar2 (10 ),
Age number (2) Check (age between 18 and 65 ),
/* Age Number (2) Check (age> = 18 and age <= 65 )*/
Lodging char (15) References lodging (lodging)
);

Create Table emp3
(Empno number (4) Constraint ABC primary key,
Ename varchar2 (10 ),
Job varchar2 (10 ),
Sex char (2) Check (sex = 'male' or sex = 'female '),
Mgr number (4 ),
Hiredate date,
Sal number (7, 2),/* salary */
Comm number (7, 2),/* bonus */
Deptno number (2 ),
Check (SAL + comm> 0 and Sal + comm <= 5000)
);

Suggestion: when designing the database table structure, we recommend that you analyze the value range of user data to describe the fields with a certain value range using check. To ensure the correctness of future data.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.