Create and modify tables in Oracle-five constraints

Source: Internet
Author: User
Oracle includes five constraints, including primary key constraints (primarykey, the value of this attribute cannot be blank, and cannot be repeated. By default, this column is automatically indexed) and foreign key constraints (foreignk

Oracle includes five constraints, including the primary key constraint (primary key, the value of this attribute cannot be blank, and cannot be repeated. By default, this column is automatically indexed) and the foreign key constraint (foreign k

Table Creation

Oracle includes five constraints, including primary key constraints (primary key, the value of this attribute cannot be blank, and cannot be repeated. By default, this column is automatically indexed) and foreign key constraints (foreign key () references rname, with reference to integrity constraints, the value of this attribute must exist in the corresponding link), non-null constraints (not null), unique constraints (unique, not repeated, but it can be null, because in the database, the returned result of the expression null = null is unknown), check constraints (check (a in (a1, a2, a3 ))),, example

Create table r1
(Id numeric (15) primary key, // primary key constraint
Name varchar2 (15) not null, // non-null Constraint
Gender varchar2 (2) check (gender in ('M', 'F', 'O'), // simulate enumeration constraints, which are not supported in Oracle
Stu_number unique, // duplicate prohibited, but can be blank
Foreign key (stu_number) references r0); // foreign key constraint

Table Modification

1. Add a new property

Alter table r add id varchar2 (10 );

2. Reduce an existing attribute

Alter table r drop name;

3. Modify the restriction of an existing attribute

Alter table test1 modify grade number (5, 2) not null;

4. Modify the attribute name of an existing attribute

Alter table test1 rename column id to stu_number;

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.