[Oracle] Table Management

Source: Internet
Author: User
Tags savepoint

Table Name and column naming rules

1. It must start with a letter
2. The length cannot exceed 30 characters
3. Oracle reserved words cannot be used
4, can only use A-Z, A-Z, 0-9, $, # and so on

Data Type

Character Type:
Char can query up to 2000 characters in length.
Varchar2 (20) is a string of up to 4000 characters.
Clob (character large object) Large Object Type up to 4 GB

Number Type:
In the range of-10, the power is 38 to the power of 10, which can be an integer or decimal.
Number (5, 2) indicates that a decimal number has five valid digits and two decimal places.
Number (5) indicates a five-digit integer.

Date type:
Date includes year, month, day, hour, minute, and second
Timestamp

Image:
Blob binary data, which can store pictures/sounds for 4 GB

Create a table:
SQL> Create Table student (
2 XH number (4), -- Student ID
3 XM varchar2 (20), -- name
4 sex char (2), -- Gender
5 birthday date, -- birthday
6 Sal number (7,2) -- scholarship amount
7 );

Add a field:
Alter table student add (classid number (2 ));

Modify the length of a field:
Alter table student modify (XM varchar2 (30 ));

Modify the type or name of a field (data is not allowed ):
Alter table student modify (XM char (30 ));

Delete a field:
Alter table student drop column Sal;

Modify the table name:
Rename student to Stu;

Delete table:
Drop table student;

Insert data:
Insert into student values (1, 'xiaoming ', 'male', '20-August 8-88', '192. 25', 12 );
Into must have

Date: day-month-year

Alter session set nls_date_format = 'yyyy-mm-dd ';

Insert some fields:
Insert null value: NULL
Select * from student where birthday is null;

Delete data:
Delete from student; logs are written, recoverable, and slow.
Truncate table student; delete all the records in the table. The table structure is still in progress. If no logs are written, the deleted records cannot be retrieved, which is fast.

Savepoint A; // savepoint B; A is overwritten by default.
Rollback to;

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.