Home  >  Article  >  Database  >  How to delete oracle field

How to delete oracle field

WBOY
WBOYOriginal
2022-01-26 10:44:1052919browse

In Oracle, you can use the "Alter Table" statement with the "Drop Column" keyword to delete fields. The syntax is "ALTER TABLE table name DROP COLUMN field name".

How to delete oracle field

The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.

How to delete oracle fields

Syntax for adding fields: alter table tablename add (column datatype [default value][null/not null],….);

Modify Field syntax: alter table tablename modify (column datatype [default value][null/not null],….);

Delete field syntax: alter table tablename drop (column);

If you add, modify, or delete multiple columns, separate them with commas.

Example of using alter table to add, delete and modify a column.

Create table structure:

create table test1
(id varchar2(20) not null);

Add a field:

alter table test1
add (name varchar2(30) default ‘无名氏’ not null);

Use one SQL statement to add three fields at the same time:

alter table test1
add (name varchar2(30) default ‘无名氏’ not null,
age integer default 22 not null,
has_money number(9,2)
);

Modify a field

alter table test1
modify (name varchar2(16) default ‘unknown’);

Another: The more formal way of writing is:

-- Add/modify columns 
alter table TABLE_NAME rename column FIELD_NAME to NEW_FIELD_NAME;

Delete a field

alter table test1
drop column name;

Recommended tutorial: "Oracle Video Tutorial"

The above is the detailed content of How to delete oracle field. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn