Вы находитесь на странице: 1из 5

tQL*Plus: Release 10.2.0.1.

0 - Production on Mon Aug 26 09:07:00 2019

Copyright (c) 1982, 2005, Oracle. All rights reserved.

SQL> connect
Enter user-name: system
Enter password:
Connected.
SQL> create table employee(empid number,name varchar(20),mail varchar(20),city
varchar(20));

Table created.

SQL> desc employee


Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NUMBER
NAME VARCHAR2(20)
MAIL VARCHAR2(20)
CITY VARCHAR2(20)

SQL> commit
2
SQL> commit;

Commit complete.

SQL> alter table employee add mobno number(10);

Table altered.

SQL> desc employee


Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NUMBER
NAME VARCHAR2(20)
MAIL VARCHAR2(20)
CITY VARCHAR2(20)
MOBNO NUMBER(10)

SQL> commit;

Commit complete.

SQL> alter table employee add (a1 varchar2(10),a2 varchar2(10));

Table altered.

SQL> desc employee


Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NUMBER
NAME VARCHAR2(20)
MAIL VARCHAR2(20)
CITY VARCHAR2(20)
MOBNO NUMBER(10)
A1 VARCHAR2(10)
A2 VARCHAR2(10)
SQL> alter table employee add(constraint un_employee unique(a1));

Table altered.

SQL> desc employee


Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NUMBER
NAME VARCHAR2(20)
MAIL VARCHAR2(20)
CITY VARCHAR2(20)
MOBNO NUMBER(10)
A1 VARCHAR2(10)
A2 VARCHAR2(10)

SQL> select constraint_name,constraint_type from user_constraints where


table_name='employee';

no rows selected

SQL> select constraint_name,constraint_type from user_constraints where


table_name='EMPLOYEE';

CONSTRAINT_NAME C
------------------------------ -
UN_EMPLOYEE U

SQL> commit;

Commit complete.

SQL> alter table employee modify (name char(30));

Table altered.

SQL> desc employee


Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NUMBER
NAME CHAR(30)
MAIL VARCHAR2(20)
CITY VARCHAR2(20)
MOBNO NUMBER(10)
A1 VARCHAR2(10)
A2 VARCHAR2(10)

SQL> commit;

Commit complete.

SQL> alter table employee modify (name not null);

Table altered.

SQL> desc employee


Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NUMBER
NAME NOT NULL CHAR(30)
MAIL VARCHAR2(20)
CITY VARCHAR2(20)
MOBNO NUMBER(10)
A1 VARCHAR2(10)
A2 VARCHAR2(10)

SQL> alter table employee drop column a2;

Table altered.

SQL> desc employee


Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NUMBER
NAME NOT NULL CHAR(30)
MAIL VARCHAR2(20)
CITY VARCHAR2(20)
MOBNO NUMBER(10)
A1 VARCHAR2(10)

SQL> commit;

Commit complete.

SQL> alter table employee drop(a1,mobno);

Table altered.

SQL> desc employee


Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NUMBER
NAME NOT NULL CHAR(30)
MAIL VARCHAR2(20)
CITY VARCHAR2(20)

SQL> alter table employee drop primary key;


alter table employee drop primary key
*
ERROR at line 1:
ORA-02441: Cannot drop nonexistent primary key

SQL> rename old employee to yee


2
SQL> rename old employee to yee;
rename old employee to yee
*
ERROR at line 1:
ORA-00946: missing TO keyword

SQL> rename employee to yee;

Table renamed.

SQL> alter table yee rename to employee;


Table altered.

SQL> desc employee;


Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NUMBER
NAME NOT NULL CHAR(30)
MAIL VARCHAR2(20)
CITY VARCHAR2(20)

SQL> commit;

Commit complete.

SQL> insert into employee values(11802601,'lokesh','lokeshjmy@gmail.com','bhopal');

1 row created.

SQL> desc employee;


Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NUMBER
NAME NOT NULL CHAR(30)
MAIL VARCHAR2(20)
CITY VARCHAR2(20)

SQL> select * from employee;

EMPID NAME MAIL


---------- ------------------------------ --------------------
CITY
--------------------
11802601 lokesh lokeshjmy@gmail.com
bhopal

SQL> set lines 256;


SQL> select * from employee;

EMPID NAME MAIL CITY


---------- ------------------------------ -------------------- --------------------
11802601 lokesh lokeshjmy@gmail.com bhopal

SQL> commit;

Commit complete.

SQL> truncate table employee;

Table truncated.

SQL> select * from employee;

no rows selected

SQL> desc employee;


Name
Null? Type
-----------------------------------------------------------------------------------
--------------------------------------------------------------- --------
-----------------------------------------------------------------------------------
----------------
EMPID
NUMBER
NAME
NOT NULL CHAR(30)
MAIL
VARCHAR2(20)
CITY
VARCHAR2(20)

SQL> drop table employee;

Table dropped.

SQL> desc employee;


ERROR:
ORA-04043: object employee does not exist

SQL>