Oracle Database Build table, delete fields, add fields, modify fields, modify fields ...

Source: Internet
Author: User

1. Create a table with Oracle:

Sql> Create TableLoginuser (2Id Number(Ten,2),  3Usernamevarchar( -),  4Passwordvarchar( -),  5Emailvarchar( -),  6Descriablevarchar2( $),  7RegDate date);

Syntax for creating tables:

CREATE TABLE table_name (    columns_name datatype,......);

Display information for creating tables:

The table is created. SQL> descUserInfo; is the name empty? type----------------------------------------- -------- ----------------------------Id Number(6) USERNAMEVARCHAR2( -) PASSWORDVARCHAR2( -) EMAILVARCHAR2( -) regdate DATE

2. Add a field information to the table:

syntax for adding fields to a table:

  

ALTER TABLE table_name     ADD column_name datatype;
Sql> Alter TableUserInfo2  AddRemarksvarchar2( -); The table has changed. SQL> descUserInfo; is the name empty? type----------------------------------------- -------- ----------------------------Id Number(6) USERNAMEVARCHAR2( -) PASSWORDVARCHAR2( -) EMAILVARCHAR2( -) regdate DATE REMARKSVARCHAR2( -)

3. Modify the field data information in the table:

Grammar:

  

ALTER TABLE table_name    MODIFY column_name datatype;
Sql> Alter TableUserInfo2Modify password Number(6,0); The table has changed. SQL> descUserInfo; is the name empty? type----------------------------------------- -------- ----------------------------Id Number(6) USERNAMEVARCHAR2( -) PASSWORD Number(6) EMAILVARCHAR2( -) regdate DATE REMARKSVARCHAR2( -)

4. Delete The fields in the table:

Delete syntax:

  

ALTER TABLE table_name     DROP COLUMN column_name;
Sql> Alter TableUserInfo2  Drop columnremarks; The table has changed. SQL> descUserInfo; is the name empty? type----------------------------------------- -------- ----------------------------Id Number(6) USERNAMEVARCHAR2( -) PASSWORD Number(6) EMAILVARCHAR2( -) regdate DATE

5. Modify the field name:

To modify the syntax:

  

ALTER TABLE  COLUMN to New_column_name;
Sql> Alter TableUserInfo2RenamecolumnEmail toNew_email; The table has changed. SQL> descUserInfo; is the name empty? type----------------------------------------- -------- ----------------------------Id Number(6) USERNAMEVARCHAR2( -) PASSWORD Number(6) New_emailVARCHAR2( -) regdate Datesql>

6. Change the name of the table:

To modify the syntax:

  

 to New_table_name;

Sql>Rename UserInfo tonew_userinfo; The table has been renamed. SQL> descUserInfo; Error:ora-04043: Object userinfo does not exist SQL> descNew_userinfo; is the name empty? type----------------------------------------- -------- ----------------------------Id Number(6) USERNAMEVARCHAR2( -) PASSWORD Number(6) New_emailVARCHAR2( -) regdate Datesql>

Oracle Database Build table, delete fields, add fields, modify fields, modify fields ...

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.