Create tables and constraints in Oracle

Source: Internet
Author: User
Creating a table in Oracle focuses on the table field type and corresponding constraints. 1. create table statement Createtabletname (Fied1 Type 1, Fied1 type 2,

Creating a table in Oracle focuses on the table field type and corresponding constraints. 1. Create table statement Create table tname (Fied1 Type 1, Fied1 type 2,

Creating a table in Oracle focuses on the table field type and corresponding constraints.

1. Create a table statement

Create table tname

(

Fied1 Type 1,

Fied1 type 2,

........

);

Create table tname as subquery -- copy existing tables

2. Field Type

Varchar (n) ---- create a field that can store n characters. The data length can be automatically extended. It is compatible with other databases and only occupies two bytes of Chinese characters and full-angle characters, numbers, each English character is a byte;

Varchar2 (n) ---- create a field that can store n characters. The data length can also be increased automatically. It is compatible with other databases. All characters are processed in two bytes (generally ).

Number (n, d) --- create a number. n is an integer, and d is the precision bit.

Date --- create Date Format Field

CLog --- stores large volumes of text

Constraints

Primary key --- Primary key constraint, uniqueness and non-null

Unique ----- uniqueness

Not Null ----- non-Null

Check ------ check and processing sex Check ('M', 'w') restrict the inserted sex field to only two types

Foreign key refrence table (fied) ----- Foreign key, associated with the fied field of the table

Statements for manually creating constraints (except foreign keys) are

Constraint nameconditon (Fild )-----

Statements for manually creating foreign keys

Constraint foreign_name foreign key (fied1) refrence t (f2 );

Modify Table Structure

Alter table tname [Add | Drop | modify] ----- You can Add, delete, or modify table fields.

Related reading:

ORA-02291: violating full constraints (*)-parent keywords not found

Obtain the table storage location and create a tablespace in Oracle

Precautions for creating and inserting tables in Oracle

Oracle creates tablespaces, creates users, authorizes, revokes permissions, deletes users, and deletes tablespaces.

Create Table, prompting ORA-00959: tablespace 'mc _ data' does not exist

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.