国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP開發(fā) oracle delete table field and oracle table add field

oracle delete table field and oracle table add field

Jan 06, 2017 am 10:52 AM

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

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

Syntax for deleting fields: alter table tablename drop (column);

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

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 a SQL statement 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;

Need to pay attention The problem is that if there are already values ??in a column, an error will occur if you want to modify the column width to be smaller than these values.

For example, if we inserted a value before

insert into test1
values ('1′,'我們很愛你');

and then modified the column: alter table test1
modify (name varchar2(8));
will You get the following error:
ERROR at line 2:
ORA-01441: Unable to reduce column length because some values ??are too large

Advanced usage:

Rename table
ALTER TABLE table_name RENAME TO new_table_name;

Modify the name of the column

Syntax:
ALTER TABLE table_name RENAME COLUMN supplier_name to sname;

Example:
alter table s_dept rename column age to age1;


Attachment: Create a table with a primary key>>

create table student (
studentid int primary key not null,
studentname varchar(8),
age int);

1. Create a primary key constraint while creating the table
(1) No naming

create table student (
studentid int primary key not null,
studentname varchar(8),
age int);

(2) Naming

create table students (
studentid int ,
studentname varchar(8),
age int,
constraint yy primary key(studentid));

2. Delete the existing primary key constraints in the table
(1) No naming
Available SELECT * from user_cons_columns;
Look up the primary key name in the table and get the primary key name in the student table SYS_C002715
alter table student drop constraint SYS_C002715;
(2) with naming
alter table students drop constraint yy;

3. Add primary key constraints to the table
alter table student add constraint pk_student primary key(studentid);

For more articles related to oracle deleting table fields and oracle table adding fields, please pay attention to PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)