Oracle table management

Source: Internet
Author: User

1. Naming rules for tables and columns
A. It must start with a letter.
B. The length cannot exceed 30 characters
C. Oracle reserved words (keywords) cannot be used)
D. Only the following characters can be used for A-Z, a-z, 0-9, $ ,#

2. Create a table
Syntax: create table Name (column name data type, column name data type ,...)
SQL> create table Student (StuNo number (10), Gender char (4), Birthday date, Address varchar (20 ));

3. Add Columns
Syntax: alter table Student add (column name data type)
SQL> alter table Student add (ClassNo char (15 ));

4. Modify the Column Length
Syntax: alter table Student modify (column name data type)
SQL> alter table Student modify (Address varchar (15 ));

5. Modify the column type
Syntax: alter table Student modify (column name data type)
SQL> alter table Student modify (Address varchar (15 ));

6. Delete Columns
Syntax: alter table Student drop column name
SQL> alter table Student drop column Address;

4. Modify the table name
Syntax: rename original table name to new table name
SQL> rename Student to Student1;

8. delete a table
Syntax: drop table Name
SQL> drop table Student;

9 insert value
Syntax: insert into Student values ("value 1", "value 2", "value 3", "value 4", "value 5 ")
SQL> insert into Student values ("09110120", "male", "27-5-1987", "Beijing, China ");

10 change the default date format
The default date format in Oracle is "dd-MON-YY"
Syntax: alter session set nls_date_format = 'new date format'
SQL> alter session set nls_date_format = 'yyyy-mm-dd'

11. Modification records
Syntax: update table name set column name = 'value 1'
SQL> update Student set Address = 'shanghai, China' where StuNo = '000000 ';

12. Delete table information
Syntax: delete from Table Name
SQL> delete from Student

14. delete a record in the table
Syntax: delete from table name where Condition
SQL> delete from Student where StuNo = '000000 ';

15. Delete the information in the table (cannot be rolled back)
Syntax: truncate table name
SQL> truncate table Student;
Features: Quick table deletion. Because no logs are written, you cannot roll back and retrieve the deleted data.

16 Create milestones
SQL> savepoint milestone name





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.