Oracle 11g Build list additions and deletions change constraint

Source: Internet
Author: User

I. Building a library

1. (Click the button with the green + sign in the upper left corner)

2. (Enter this interface, PASSOWRD is the password.) When you are finished, click on the Test button in the row below and click Connect without exception.

Two. Build a table

1-1. Create TABLE Name 1 (

Tid Number (4)--primary key column-level constraint (primary key),

Tname varchar (--ont) NULL non-null constraint, can only be defined at the column-level constraints,

Tsex varchar2 (2)--check (tsex= ' male ' or tsex= ' female ') checks the constraint,

taddress varchar (30),

Constraint table name 1_TID_PK primary KEY (TID),--table-level constraint (primary key)

)

1-2. Create TABLE Name 2 (

Tid Number (4),

Sname VARCHAR2 (10),

Comstraint table name 2_TID_FK foreign key (TID) References table name 1 (TID),--table-level FOREIGN KEY constraint

)

Three. Increase

1-1. Inserting one piece of data at a time

Insert into table name (tid,tname,tsex,taddress)--the field can be omitted but the corresponding

VALUES (1, ' Zhang San ', ' Male ', ' earth ')

1-2. Inserting multiple data at once

Insert INTO table name

Select 2, ' John Doe ', ' Male ', ' earth ' from dual

UNION ALL

Select 3, ' Zhao Wu ', ' Male ', ' earth ' from dual

UNION ALL

Select 4, ' King VI ', ' Male ', ' earth ' from dual

(Note: Dual is a virtual table used to form the Select syntax rule, dual has only one record.) Dual is a table for SYS users, public, and other user can use it. )

Four. by deleting

1-1. drop table text; --Delete table with table name text

1-2. Delete from text--delete all table records for table text

1-3. Delete from text--delete table record with text field ID equal to 2

where id = 2;

Five. Change

1. Update student Set name = ' Lily '--Change the name of the student table to ' Ya ya ' to ' lily '

where name = ' Ya Ya '

Six. Check

1. Select * FROM table name EMP--Query all records with a table named EMP

Seven. Constraints

1-1. Primary KEY (abbreviation: PK)--PRIMARY KEY constraint

1-2. Ont null (short name: NN)--Non-null constraint

1-3. Unique (abbreviation: UQ)--Unique constraint

1-4. Check (abbreviation: CK)-checking constraints

1-5. Foreign key ("FK")--FOREIGN KEY constraint

Constraints are divided into: column-level constraints and table-level constraints

Column-level constraints: Writing on the last side of a column

Table-level constraints: sibling to other fields

(Note:: Constraint details with code on?? )

Oracle 11g Build list additions and deletions change constraint

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.