Table operations in oracle and table operations in oracle

Source: Internet
Author: User

Table operations in oracle and table operations in oracle

The basic creation will not be mentioned. Here we will talk about some uncommon methods, which means they are easy to use.

Create a table using a subquery
Create a new book table using a subquery.

<Span style = "white-space: pre"> </span> Step 1: completely copy the book table to "Book 1", and run the following command: create table Book 1 as select * FROM book; Step 2: CREATE a new book TABLE "Book 2" that only contains the title and unit price. Enter and execute the following command: create table Book 2 (title, unit price) as select book name, unit price FROM book;
<Span style = "white-space: pre"> </span> Step 3: Create a new book table "Book 3", which only contains the title and unit price, but does not copy the content, enter and execute the following command: <span style = "white-space: pre"> </span> create table Book 3 (title, unit price) as select book name, unit Price FROM book WHERE 1 = 2;
Set the column Default Value
You can specify the column DEFAULT value when creating a table. The DEFAULT value is described in the DEFAULT part.

<Span style = "white-space: pre"> </span> book name VARCHAR2 (30) DEFAULT 'unknown ', Press No. VARCHAR2 (2) default null, <span style = "white-space: pre"> </span> borrow quantity NUMBER (3) DEFAULT 0

Delete A created table
The TABLE owner must be the TABLE creator or have the permission to drop any table.

<Span style = "white-space: pre"> </span> drop table Book 1;
Rename a table
Only the table owner can modify the table name.
<Span style = "white-space: pre"> </span> change the "books" table TO "Books 5" table: RENAME book TO Book 5;
Clear table
Syntax:
Truncate table name;
Clear a table to delete all the data in the table and release the occupied storage space.

View table
You can query the data dictionary USER_OBJECTS to display all tables of users in the current mode.
Displays all tables of the current user. SELECT object_name FROM user_objects WHERE object_type = 'table ';

So much .. I hope you will pay attention to it later.

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.