Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
13 views9 pages

CH DBMSLab

The document outlines a series of SQL commands executed to manage a database user and create an 'Employee' table. It includes user creation, granting privileges, inserting records, and modifying table structures, along with error handling for various SQL operations. The final state shows the successful creation of the 'Employee' table with several entries and constraints applied.

Uploaded by

Pallavi K Pyati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views9 pages

CH DBMSLab

The document outlines a series of SQL commands executed to manage a database user and create an 'Employee' table. It includes user creation, granting privileges, inserting records, and modifying table structures, along with error handling for various SQL operations. The final state shows the successful creation of the 'Employee' table with several entries and constraints applied.

Uploaded by

Pallavi K Pyati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

SQL> connect

Enter user-name: sys as sysdba


Enter password: *******
Connected.
SQL> create user charan identified by tiger;
create user charan identified by tiger
*
ERROR at line 1:
ORA-01920: user name 'CHARAN' conflicts with another user or rol

SQL> drop user charan;

User dropped.

SQL> create user charan identified by tiger;

User created.

SQL> grant connect resource,dba to charan;


grant connect resource,dba to charan
*
ERROR at line 1:
ORA-00990: missing or invalid privilege

SQL> grant connect,resource,dba to charan;

Grant succeeded.

SQL> connect
Enter user-name: charan
Enter password: *****
Connected.
----------------------------------------------------------
SQL> create table Employee
2 (
3 EmpNo int,
4 EName varchar(20),
5 Job varchar(20),
6 Manager_No int,
7 Sal Decimal,
8 Commission Decimal);

SQL> desc Employee;


Name Null? Type
----------------------------------------- -------- ----------------------------
EMPNO NUMBER(38)
ENAME VARCHAR2(20)
JOB VARCHAR2(20)
MANAGER_NO NUMBER(38)
SAL NUMBER(38)
COMMISSION NUMBER(38)

SQL> insert into employee values(1,'Ramesh',"Engineer",20,10000,500);


insert into employee values(1,'Ramesh',"Engineer",20,10000,500)
*
ERROR at line 1:
ORA-00984: column not allowed here
SQL> insert into employee values(1,'Ramesh','Engineer',20,10000,500);

1 row created.

SQL>
Wrote file afiedt.buf

1* insert into employee values(1,'Ramesh','Engineer',20,10000,500)


SQL>
Wrote file afiedt.buf

1* insert into employee values(1,'Ramesh','Engineer',20,10000,500)


SQL> insert into employee values(2,'Suresh','Doctor',21,20000,1000);

1 row created.

SQL> insert into employess values(3,'prakash','Clerk',22,5000,200);


insert into employess values(3,'prakash','Clerk',22,5000,200)
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> insert into employee values(3,'prakash','Clerk',22,5000,200);

1 row created.

SQL> select * from employee;

EMPNO ENAME JOB MANAGER_NO SAL


---------- -------------------- -------------------- ---------- ----------
COMMISSION
----------
1 Ramesh Engineer 20 10000
500

2 Suresh Doctor 21 20000


1000

3 prakash Clerk 22 5000


200

SQL> /

EMPNO ENAME JOB MANAGER_NO SAL


---------- -------------------- -------------------- ---------- ----------
COMMISSION
----------
1 Ramesh Engineer 20 10000
500

2 Suresh Doctor 21 20000


1000

3 prakash Clerk 22 5000


200
SQL> /

EMPNO ENAME JOB MANAGER_NO SAL


---------- -------------------- -------------------- ---------- ----------
COMMISSION
----------
1 Ramesh Engineer 20 10000
500

2 Suresh Doctor 21 20000


1000

3 prakash Clerk 22 5000


200

SQL> set pagesize 500


SQL> /

EMPNO ENAME JOB MANAGER_NO SAL


---------- -------------------- -------------------- ---------- ----------
COMMISSION
----------
1 Ramesh Engineer 20 10000
500

2 Suresh Doctor 21 20000


1000

3 prakash Clerk 22 5000


200

SQL> set linesize 200


SQL> /

EMPNO ENAME JOB MANAGER_NO SAL


COMMISSION
---------- -------------------- -------------------- ---------- ----------
----------
1 Ramesh Engineer 20 10000
500
2 Suresh Doctor 21 20000
1000
3 prakash Clerk 22 5000
200

SQL> select * from employee;

EMPNO ENAME JOB MANAGER_NO SAL


COMMISSION
---------- -------------------- -------------------- ---------- ----------
----------
1 Ramesh Engineer 20 10000
500
2 Suresh Doctor 21 20000
1000
3 prakash Clerk 22 5000
200

SQL> rollback;

Rollback complete.

SQL> select * from employee;

no rows selected

SQL> desc employee;


Name
Null? Type

-----------------------------------------------------------------------------------
------------------------------ -------- ----------------------------------
EMPNO
NUMBER(38)
ENAME
VARCHAR2(20)
JOB
VARCHAR2(20)
MANAGER_NO
NUMBER(38)
SAL
NUMBER(38)
COMMISSION
NUMBER(38)

SQL> alter table employee add constraint pk_EMPNO primary key(EMPNO);

Table altered.

SQL> desc employee;


Name
Null? Type

-----------------------------------------------------------------------------------
------------------------------ -------- ------------------------
EMPNO
NOT NULL NUMBER(38)
ENAME
VARCHAR2(20)
JOB
VARCHAR2(20)
MANAGER_NO
NUMBER(38)
SAL
NUMBER(38)
COMMISSION
NUMBER(38)

SQL> alter table employee modify column ENAME not null;


alter table employee modify column ENAME not null
*
ERROR at line 1:
ORA-00905: missing keyword
SQL> alter table employee modify column ENAME varchar(20) not null;
alter table employee modify column ENAME varchar(20) not null
*
ERROR at line 1:
ORA-00905: missing keyword

SQL> alter table employee modify ENAME varchar(20) not null;

Table altered.

SQL> desc employee;


Name
Null? Type

-----------------------------------------------------------------------------------
------------------------------ -------- ------------------------
EMPNO
NOT NULL NUMBER(38)
ENAME
NOT NULL VARCHAR2(20)
JOB
VARCHAR2(20)
MANAGER_NO
NUMBER(38)
SAL
NUMBER(38)
COMMISSION
NUMBER(38)

SQL> alter table employee modify Job varchar(30) not null;

Table altered.

SQL> desc employee


Name
Null? Type

-----------------------------------------------------------------------------------
------------------------------ -------- ------------------------
EMPNO
NOT NULL NUMBER(38)
ENAME
NOT NULL VARCHAR2(20)
JOB
NOT NULL VARCHAR2(30)
MANAGER_NO
NUMBER(38)
SAL
NUMBER(38)
COMMISSION
NUMBER(38)

SQL> alter table employee modify Manager_No not null;

Table altered.

SQL> desc employee


Name
Null? Type

-----------------------------------------------------------------------------------
------------------------------ -------- ------------------------
EMPNO
NOT NULL NUMBER(38)
ENAME
NOT NULL VARCHAR2(20)
JOB
NOT NULL VARCHAR2(30)
MANAGER_NO
NOT NULL NUMBER(38)
SAL
NUMBER(38)
COMMISSION
NUMBER(38)

SQL> alter table employee modify sal not null, commission not null;
alter table employee modify sal not null, commission not null
*
ERROR at line 1:
ORA-01735: invalid ALTER TABLE option

SQL> alter table employee modify sal not null


2 modify commission not null;

Table altered.

SQL> desc employee


Name
Null? Type

-----------------------------------------------------------------------------------
------------------------------ -------- ------------------------
EMPNO
NOT NULL NUMBER(38)
ENAME
NOT NULL VARCHAR2(20)
JOB
NOT NULL VARCHAR2(30)
MANAGER_NO
NOT NULL NUMBER(38)
SAL
NOT NULL NUMBER(38)
COMMISSION
NOT NULL NUMBER(38)

SQL> alter table employee modify ename null;

Table altered.

SQL> desc employee


Name
Null? Type

-----------------------------------------------------------------------------------
------------------------------ -------- ------------------------
EMPNO
NOT NULL NUMBER(38)
ENAME
VARCHAR2(20)
JOB
NOT NULL VARCHAR2(30)
MANAGER_NO
NOT NULL NUMBER(38)
SAL
NOT NULL NUMBER(38)
COMMISSION
NOT NULL NUMBER(38)

SQL> alter table employee modify job null


2 modify manager_no null
3 modify sal null;

Table altered.

SQL> desc employee


Name
Null? Type

-----------------------------------------------------------------------------------
------------------------------ -------- ------------------------
EMPNO
NOT NULL NUMBER(38)
ENAME
VARCHAR2(20)
JOB
VARCHAR2(30)
MANAGER_NO
NUMBER(38)
SAL
NUMBER(38)
COMMISSION
NOT NULL NUMBER(38)

SQL> alter table employee modify ename not null, modify job not null, modify sal
not null;
alter table employee modify ename not null, modify job not null, modify sal not
null
*
ERROR at line 1:
ORA-01735: invalid ALTER TABLE option

SQL> alter table employee modify ( ename not null, sal not null);

Table altered.

SQL> desc employee


Name
Null? Type

-----------------------------------------------------------------------------------
------------------------------ -------- ------------------------
EMPNO
NOT NULL NUMBER(38)
ENAME
NOT NULL VARCHAR2(20)
JOB
VARCHAR2(30)
MANAGER_NO
NUMBER(38)
SAL
NOT NULL NUMBER(38)
COMMISSION
NOT NULL NUMBER(38)

SQL> insert into employee values(4,'Girish','',,15000,100);


insert into employee values(4,'Girish','',,15000,100)
*
ERROR at line 1:
ORA-00936: missing expression

SQL> insert into employee(empno,ename,job,manager_no,sal,commission)


values(4,'Girish','',,15000,100);
insert into employee(empno,ename,job,manager_no,sal,commission)
values(4,'Girish','',,15000,100)

*
ERROR at line 1:
ORA-00936: missing expression

SQL> insert into employee(empno,ename,job,manager_no,sal,commission)


values(4,'Girish','','',15000,100);

1 row created.

SQL> select * from employee;

EMPNO ENAME JOB MANAGER_NO


SAL COMMISSION
---------- -------------------- ------------------------------ ----------
---------- ----------
4 Girish
15000 100

SQL> commit;

Commit complete.

SQL> select * from employee;

EMPNO ENAME JOB MANAGER_NO


SAL COMMISSION
---------- -------------------- ------------------------------ ----------
---------- ----------
4 Girish
15000 100

SQL> insert into employee(empno,ename,job,manager_no,sal,commission)


values(4,'Girish','','',15000,100);
insert into employee(empno,ename,job,manager_no,sal,commission)
values(4,'Girish','','',15000,100)
*
ERROR at line 1:
ORA-00001: unique constraint (CHARAN.PK_EMPNO) violated

SQL> insert into employee(empno,ename,job,manager_no,sal,commission)


values(5,'Pranesh',null,'',20000,300);

1 row created.

SQL> select * from employee;

EMPNO ENAME JOB MANAGER_NO


SAL COMMISSION
---------- -------------------- ------------------------------ ----------
---------- ----------
4 Girish
15000 100
5 Pranesh
20000 300

SQL> rollback;

Rollback complete.

SQL> select * from employee;

EMPNO ENAME JOB MANAGER_NO


SAL COMMISSION
---------- -------------------- ------------------------------ ----------
---------- ----------
4 Girish
15000 100

SQL> commit;

Commit complete.

SQL>
SQL> select * from employee;

EMPNO ENAME JOB MANAGER_NO


SAL COMMISSION
---------- -------------------- ------------------------------ ----------
---------- ----------

You might also like