The addition and deletion of Oracle table fields, the renaming of tables, and the addition and deletion of primary keys

Time:2020-5-9

1、 Add, delete and modify table fields:

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

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

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

Note: if multiple columns are added, modified, or deleted, separate them with commas.

Rename the table field: alter table tablename rename column field name to new field name;

2、 Rename table:

alter table tablename rename to new_table_name;

3、 To add, delete, or modify a primary key:

Lookup table constraint:select constraint_name from user_cons_columns a where a.table_name='tablename';

Add table constraint:alter table tablename add constraint pk_name primary key(column);

Delete table constraint:alter table tablename drop constraint constraint_name----(SYS_C002715);

Modify table constraint: 1) disable table primary key:alter table tablename disable primary key;

2) enable table primary key:alter table tablename enable primary key;

3) rename table primary key:alter table tablename rename constraint pk_id to new_pk_id;

The above is the whole content of this article, I hope that the content of this article can bring some help to your study or work, and also hope to support developepaer!