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.