Vous êtes sur la page 1sur 2

--Managing schema objects

1)create table
2)add column
3)modify column
4)rename column
5)drop column
6)UNUSED OPTION
[oracle@oracle10g ~]$ export ORACLE_SID=test
[oracle@oracle10g ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sun May 26 20:09:28 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> conn hr/hr
Connected.
SQL> create table tab_edit (id number, name varchar2(20));
Table created.
SQL> alter table tab_edit add dept_id number;
Table altered.
SQL> desc tab_edit
Name
Null?
----------------------------------------- -------ID
NAME
DEPT_ID

Type
---------------------------NUMBER
VARCHAR2(20)
NUMBER

SQL> insert into tab_edit values(1,'Mohan',10);


1 row created.
SQL> commitl
SP2-0042: unknown command "commitl" - rest of line ignored.
SQL> commit;
Commit complete.
SQL> alter table tab_edit add salary number;
Table altered.
SQL> select * from tab_edit;
ID NAME
DEPT_ID
SALARY
---------- -------------------- ---------- ---------1 Mohan
10
SQL> alter table tab_edit modify salary number(10);
Table altered.

SQL> desc tab_edit


Name
Null?
----------------------------------------- -------ID
NAME
DEPT_ID
SALARY

Type
---------------------------NUMBER
VARCHAR2(20)
NUMBER
NUMBER(10)

SQL> alter table tab_edit rename column dept_id to dept_num;


Table altered.
SQL> desc tab_edit
Name
Null?
----------------------------------------- -------ID
NAME
DEPT_NUM
SALARY

Type
---------------------------NUMBER
VARCHAR2(20)
NUMBER
NUMBER(10)

SQL> alter table tab_edit drop column salary;


Table altered.
SQL> desc tab_edit
Name
Null?
----------------------------------------- -------ID
NAME
DEPT_NUM

Type
---------------------------NUMBER
VARCHAR2(20)
NUMBER

**UNUSED COLUMNS
SQL> alter table tab_edit set unused column dept_num;
Table altered.
SQL> desc tab_edit
Name
Null?
----------------------------------------- -------ID
NAME
SQL> select * from tab_edit;
ID NAME
---------- -------------------1 Mohan
To drop unused columns:
SQL> alter table tab_edit drop unused columns;
Table altered.
--Flashback table to before drop.

Type
---------------------------NUMBER
VARCHAR2(20)

Vous aimerez peut-être aussi