Creation of primary key, foreign key, compound foreign key

Source: Internet
Author: User

--PRIMARY key
CREATE TABLE EMP (ID number constraint ID_PR primary key, name1 varchar (8));
CREATE TABLE EMP9 (ID number, name1 varchar (8), constraint ABA_PR primary key (ID,NAME1));
--FOREIGN key
CREATE TABLE EMP1 (ID number references emp (ID), name varchar (8));

--composite FOREIGN key
CREATE TABLE Emp0 (ID number, name varchar (8), Constraint fk_nam1e foreign key (id,name) references EMP9 (id,name1));


--PRIMARY key addition
CREATE TABLE EMP2 (ID number,name varchar (8), id1 number, constraint pk_id primary key (ID), Constraint fk_name foreign key (ID 1) references emp (ID))
The wording of--check constraint
CREATE TABLE Emp4 (ID number check (ID in (3)), name varchar (8));

Without a constraint name:
CREATE TABLE UserInfo (
ID Number (6) primary key,--primary key
Name VARCHAR2 () NOT null,--non-null
Sex number (1),
Age Number (3) default 18,
Birthday date,
Address VARCHAR2 (50),
Email varchar2 Unique,--only
Tel Number (11),
Deptno Number (2) References Dept (DEPTNO)-FOREIGN key
);

Creation of primary key, foreign key, compound foreign key

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.