Oracle table Building, primary key, foreign key basic syntax ____oracle

Source: Internet
Author: User
Oracle Table-Building, primary key, foreign key basic syntax


-Create TABLE syntax:
CREATE TABLE Table name (
Field name 1 field type (length) is empty,
Field Name 2 field type is NULL
);

-Add primary key
ALTER TABLE name add constraint primary Key name primary key (field name 1);

-Add foreign keys:
ALTER TABLE name
Add constraint foreign Key name foreign key (field name 1)
References Association table (field name 2);

specify primary key and foreign key when creating a table

CREATE TABLE T_stu (
stu_id char (5) NOT NULL,
Stu_name VARCHAR2 (8) NOT NULL,
Constraint Pk_t_stu primary KEY (STU_ID)
);


the primary key and the foreign key are established together:
CREATE TABLE T_score (
Exam_score number (5,2),
Exam_date DATE,
Autoid number is not NULL,
stu_id char (5),
sub_id char (3),
Constraint Pk_t_score primary KEY (Autoid),
Constraint Fk_t_score_refe foreign key (stu_id)
References T_stu (stu_id)
)

Related Article

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.