Sie sind auf Seite 1von 4

Program no 4.

Perform the following

1.Rename the table dept as department.

2.Add a new column PINCODE with not null constraints to the existing table DEPT.

3.All constraints and views that reference the column are dropped automatically along
with all column.

4.Rename the column DNAME to DEPT_NAME in dept table.

5. Change the datatype of column loc as CHAR with size 10.

6. Delete table.

create table dept(deptno integer,dname varchar(10),loc varchar(10),primary key(deptno));

desc dept;

table created.

desc dept;

T abl e Col umn Dat a T ype Lengt h Pr eci si on Scal e Pr imar y Key Null abl e Def aul t Comment
DEPT DEPTNO Number - - 0 1 - - -

DNAME Varchar2 10 - - - - -

LOC Varchar2 10 - - - - -

1.Rename the table dept as department.

alter table dept rename to department;


Table altered.

desc department;
T abl e Col umn Dat a T ype Lengt h Pr eci si on Scal e Pr imar y Key Null abl e Def aul t Comment

DEPARTMENT DEPTNO Number - - 0 1 - - -

DNAME Varchar2 10 - - - - -

LOC Varchar2 10 - - - - -

2.Add a new column PINCODE with not null constraints to the existing table DEPT.

alter table department add(pincode number(6)not null);


Table altered.

desc department;

T abl e Col umn Dat a T ype Lengt h Pr eci si on Scal e Pr imar y Key Null abl e Def aul t Comment

DEPARTMENT DEPTNO Number - - 0 1 - - -

DNAME Varchar2 10 - - - - -

LOC Varchar2 10 - - - - -

PINCODE Number - 6 0 - - - -

3.All constraints and views that reference the column are dropped automatically along
with all column.

alter table department drop column LOC CASCADE CONSTRAINTS;


Table dropped.

desc department;

T abl e Col umn Dat a T ype Lengt h Pr eci si on Scal e Pr imar y Key Null abl e Def aul t Comment

DEPARTMENT DEPTNO Number - - 0 1 - - -

DNAME Varchar2 10 - - - - -
PINCODE Number - 6 0 - - - -

4.Rename the column DNAME to DEPT_NAME in dept table.

alter table department rename column dname to dept_name;


Table altered.

Dat a Lengt Pr eci si o Scal Pr imar y Null abl Def aul Comme
T abl e Col umn T ype h n e Key e t nt
DEPARTME
DEPTNO Number - - 0 1 - - -
NT
DEPT_NAM
Varchar2 10 - - - - -
E
PINCODE Number - 6 0 - - - -

5. Change the datatype of column loc as CHAR with size 10.

create table dept1(deptno integer,dname varchar(10),loc varchar(10),primary


key(deptno));

table created.

Alter table department modify loc char(10);


Table altered.

desc dept1;

T abl e Col umn Dat a T ype Lengt h Pr eci si on Scal e Pr imar y Key Null abl e Def aul t Comment

DEPT1 DEPTNO Number - - 0 1 - - -

DNAME Varchar2 10 - - - - -

LOC Char 10 - - - - -

6. Delete table.
drop table department;
Table dropped.

desc department;
Object to be described could not be found.

Das könnte Ihnen auch gefallen