Oracle SQL BASICS (1)-create and modify tables, oraclesql

Source: Internet
Author: User

Oracle SQL BASICS (1)-create and modify tables, oraclesql

1. Table creation statement

Create table fdh_client_info (

Id varchar2 (50) primary key,

Name varchar2 (30) not null,

Sex varchar (1 ),

Age number (3 ),

Address varchar2 (300)

);

2. Modify the table name

Method 1:

Alter table fdh_client_info rename to fdh_client;

Method 2: (only tables under the current schema can be modified)

RENAME fdh_client TO fdh_client_info;

Method 3:

Create table fdh_client_new AS select * from fdh_client_info;

Drop table fdh_client_info;

3. Modify columns

① Add a column

Alter table fdh_client ADD (city varchar2 (100), is_vip varchar (1) default 'n'); -- added two columns

② Delete a column

Alter table fdh_client DROP (city); -- it is required to delete only one column of parentheses;

③ Modify the column name

Alter table fdh_client rename column city TO province;

④ Modify the column type and length

Alter table fdh_client MODIFY (province varchar (80) default 'unknow' not null );

Note: a. You can modify attributes such as the type, field length, and default value constraints when modifying a column;

B. If the modified column contains the not null constraint, the corresponding fields of all records in the table cannot be blank;

C. You can delete a column and add a new column to modify the column.

4. delete a table

Drop table fdh_client_new;

Drop table cp_customer cascade constraint; -- cascade TABLE deletion (delete the TABLE associated with the foreign key to the current TABLE at the same time)

5. Add comments

Comment on table fdh_client IS 'customer test table ';

Comment on column fdh_client.province IS 'province ';

 

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.