0% found this document useful (0 votes)
4 views15 pages

TCL & DCL

The document details a series of SQL commands executed by a user to create and manipulate tables in a database. It includes creating a table, inserting records, updating values, rolling back transactions, and managing user privileges. The document also shows attempts to grant and revoke permissions, as well as error messages encountered during these operations.

Uploaded by

gcetly.2
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)
4 views15 pages

TCL & DCL

The document details a series of SQL commands executed by a user to create and manipulate tables in a database. It includes creating a table, inserting records, updating values, rolling back transactions, and managing user privileges. The document also shows attempts to grant and revoke permissions, as well as error messages encountered during these operations.

Uploaded by

gcetly.2
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/ 15

SQL> connect

Enter user-name: student29


Enter password:
Connected.
SQL> create table table9(sno int,name varchar(20),age int);

Table created.

SQL> desc table9;


Name Null? Type
----------------------------------------- -------- ----------------------------
SNO NUMBER(38)
NAME VARCHAR2(20)
AGE NUMBER(38)

SQL> insert into table9 values('&sno','&name','&age');


Enter value for sno: 52
Enter value for name: varshashri
Enter value for age: 18
old 1: insert into table9 values('&sno','&name','&age')
new 1: insert into table9 values('52','varshashri','18')

1 row created.

SQL> /
Enter value for sno: 12
Enter value for name: anu
Enter value for age: 21
old 1: insert into table9 values('&sno','&name','&age')
new 1: insert into table9 values('12','anu','21')

1 row created.

SQL> /
Enter value for sno: 23
Enter value for name: shri
Enter value for age: 12
old 1: insert into table9 values('&sno','&name','&age')
new 1: insert into table9 values('23','shri','12')

1 row created.

SQL> /
Enter value for sno: 45
Enter value for name: uma
Enter value for age: 25
old 1: insert into table9 values('&sno','&name','&age')
new 1: insert into table9 values('45','uma','25')

1 row created.

SQL> /
Enter value for sno: 44
Enter value for name: bruntha
Enter value for age: 22
old 1: insert into table9 values('&sno','&name','&age')
new 1: insert into table9 values('44','bruntha','22')
1 row created.

SQL> select *from table9;

SNO NAME AGE


---------- -------------------- ----------
52 varshashri 18
12 anu 21
23 shri 12
45 uma 25
44 bruntha 22

SQL> savepoint a1;

Savepoint created.

SQL> update table9 set age=20 where sno=52;

1 row updated.

SQL> rollback to a1;

Rollback complete.

SQL> update table9 set age=20 where sno=52;

1 row updated.

SQL> select *from table9;

SNO NAME AGE


---------- -------------------- ----------
52 varshashri 20
12 anu 21
23 shri 12
45 uma 25
44 bruntha 22

SQL> rollback to a1;

Rollback complete.

SQL> select *from table9;

SNO NAME AGE


---------- -------------------- ----------
52 varshashri 18
12 anu 21
23 shri 12
45 uma 25
44 bruntha 22

SQL> update table9 set age=20 where name=uma;


update table9 set age=20 where name=uma
*
ERROR at line 1:
ORA-00904: "UMA": invalid identifier
SQL> update table9 set age=20 where name='uma';

1 row updated.

SQL> savepoint a2;

Savepoint created.

SQL> update table9 set age=20 where name='anu';

1 row updated.

SQL> update table9 set age=20 where name='shri';

1 row updated.

SQL> rollback to a2;

Rollback complete.

SQL> select *from table9;

SNO NAME AGE


---------- -------------------- ----------
52 varshashri 18
12 anu 21
23 shri 12
45 uma 20
44 bruntha 22

SQL> rollback to a1;

Rollback complete.

SQL> select *from table9;

SNO NAME AGE


---------- -------------------- ----------
52 varshashri 18
12 anu 21
23 shri 12
45 uma 25
44 bruntha 22

SQL> commit;

Commit complete.

SQL> rollback to a2;


rollback to a2
*
ERROR at line 1:
ORA-01086: savepoint 'A2' never established

SQL> rollback to a1;


rollback to a1
*
ERROR at line 1:
ORA-01086: savepoint 'A1' never established

SQL> create user user1 identified by user1;

User created.

SQL> connect user1


Enter password:
ERROR:
ORA-01045: user USER1 lacks CREATE SESSION privilege; logon denied

Warning: You are no longer connected to ORACLE.


SQL> connect
Enter user-name: student29
Enter password:
Connected.
SQL> grant connect to user1;

Grant succeeded.

SQL> connect
Enter user-name: student29
Enter password:
Connected.
SQL> grant create table to user1;

Grant succeeded.

SQL> create table tab1(rn int,sno int,name varchar(20),dept varchar(20));

Table created.

SQL> desc tab1;


Name Null? Type
----------------------------------------- -------- ----------------------------
RN NUMBER(38)
SNO NUMBER(38)
NAME VARCHAR2(20)
DEPT VARCHAR2(20)

SQL> grant resurces to user1;


grant resurces to user1
*
ERROR at line 1:
ORA-01919: role 'RESURCES' does not exist

SQL> insert into tabl values('&rn','&sno','&name','&dept');


Enter value for rn: 1
Enter value for sno: 52
Enter value for name: varshashri
Enter value for dept: cse
old 1: insert into tabl values('&rn','&sno','&name','&dept')
new 1: insert into tabl values('1','52','varshashri','cse')
insert into tabl values('1','52','varshashri','cse')
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> connect
Enter user-name: user1
Enter password:
Connected.
SQL> create table tab1(rn int,sno int,name varchar(20),dept varchar(20));
create table tab1(rn int,sno int,name varchar(20),dept varchar(20))
*
ERROR at line 1:
ORA-01950: no privileges on tablespace 'SYSTEM'

SQL> connect
Enter user-name: student29
Enter password:
Connected.

SQL> grant connect,dba to user1;

Grant succeeded.

SQL> connect
Enter user-name: user1
Enter password:
Connected.
SQL> create table tab1(rn int,sno int,name varchar(20),dept varchar(20));

Table created.

SQL> desc tab1;


Name Null? Type
----------------------------------------- -------- ----------------------------
RN NUMBER(38)
SNO NUMBER(38)
NAME VARCHAR2(20)
DEPT VARCHAR2(20)

SQL> insert into tab1 values('&rn','&sno','name','dept');


Enter value for rn: 1
Enter value for sno: 52
old 1: insert into tab1 values('&rn','&sno','name','dept')
new 1: insert into tab1 values('1','52','name','dept')

1 row created.

SQL> insert into tab1 values('&rn','&sno','&name','&dept');


Enter value for rn: 2
Enter value for sno: 22
Enter value for name: bhgfu
Enter value for dept: cse
old 1: insert into tab1 values('&rn','&sno','&name','&dept')
new 1: insert into tab1 values('2','22','bhgfu','cse')

1 row created.

SQL> select *from tab1;


RN SNO NAME DEPT
---------- ---------- -------------------- --------------------
1 52 name dept
2 22 bhgfu cse

SQL> update tab1 set name='ghjj' where name='name';

1 row updated.

SQL> select *from tab1;

RN SNO NAME DEPT


---------- ---------- -------------------- --------------------
1 52 ghjj dept
2 22 bhgfu cse

SQL> update tab1 set name='eee' where dept='dept';

1 row updated.

SQL>
SQL> select *from tab1;

RN SNO NAME DEPT


---------- ---------- -------------------- --------------------
1 52 eee dept
2 22 bhgfu cse

SQL> insert into tab1 values('&rn','&sno','&name','&dept');


Enter value for rn: 3
Enter value for sno: 56
Enter value for name: dghjj
Enter value for dept: mech
old 1: insert into tab1 values('&rn','&sno','&name','&dept')
new 1: insert into tab1 values('3','56','dghjj','mech')

1 row created.

SQL> /
Enter value for rn: 4
Enter value for sno: 77
Enter value for name: htkyt
Enter value for dept: ece
old 1: insert into tab1 values('&rn','&sno','&name','&dept')
new 1: insert into tab1 values('4','77','htkyt','ece')

1 row created.

SQL> /
Enter value for rn: 5
Enter value for sno: 23
Enter value for name: fhkkl
Enter value for dept: cse
old 1: insert into tab1 values('&rn','&sno','&name','&dept')
new 1: insert into tab1 values('5','23','fhkkl','cse')

1 row created.
SQL> /
Enter value for rn: 6
Enter value for sno: 44
Enter value for name: fhgf
Enter value for dept: civil
old 1: insert into tab1 values('&rn','&sno','&name','&dept')
new 1: insert into tab1 values('6','44','fhgf','civil')

1 row created.

SQL> select *from tab1;

RN SNO NAME DEPT


---------- ---------- -------------------- --------------------
1 52 eee dept
2 22 bhgfu cse
3 56 dghjj mech
4 77 htkyt ece
5 23 fhkkl cse
6 44 fhgf civil

6 rows selected.

SQL> delete from tab1 where sno=77;

1 row deleted.

SQL> select *from tab1;

RN SNO NAME DEPT


---------- ---------- -------------------- --------------------
1 52 eee dept
2 22 bhgfu cse
3 56 dghjj mech
5 23 fhkkl cse
6 44 fhgf civil

SQL> update tab1 set dept='dept' where name='eee';

1 row updated.

SQL> select *from tab1;

RN SNO NAME DEPT


---------- ---------- -------------------- --------------------
1 52 eee dept
2 22 bhgfu cse
3 56 dghjj mech
5 23 fhkkl cse
6 44 fhgf civil
SQL> select *from all_users;

USERNAME USER_ID CREATED


------------------------------ ---------- ---------
USER1 38 01-APR-24
USER29 37 18-MAR-24
STUDENT29 36 18-MAR-24
FLOWS_020100 35 07-FEB-06
FLOWS_FILES 34 07-FEB-06
HR 33 07-FEB-06
MDSYS 32 07-FEB-06
ANONYMOUS 28 07-FEB-06
XDB 27 07-FEB-06
CTXSYS 25 07-FEB-06
DBSNMP 23 07-FEB-06

USERNAME USER_ID CREATED


------------------------------ ---------- ---------
TSMSYS 20 07-FEB-06
DIP 18 07-FEB-06
OUTLN 11 07-FEB-06
SYSTEM 5 07-FEB-06
SYS 0 07-FEB-06

16 rows selected.

SQL> revoke dba from user1;

Revoke succeeded.

SQL> connect
Enter user-name: user1
Enter password:
Connected.
SQL> select *from tab1;

RN SNO NAME DEPT


---------- ---------- -------------------- --------------------
1 52 eee dept
2 22 bhgfu cse
3 56 dghjj mech
5 23 fhkkl cse
6 44 fhgf civil

SQL> update tab1 set dept='dept' where name='eee';

1 row updated.

SQL> revoke create,update,insert from user1;


revoke create,update,insert from user1
*
ERROR at line 1:
ORA-01919: role 'CREATE' does not exist

SQL> revoke create table,update,insert from user1;


revoke create table,update,insert from user1
*
ERROR at line 1:
ORA-01031: insufficient privileges

SQL> revoke update from user1;


revoke update from user1
*
ERROR at line 1:
ORA-01919: role 'UPDATE' does not exist
SQL> revoke update on tab1 from user1;
revoke update on tab1 from user1
*
ERROR at line 1:
ORA-01749: you may not GRANT/REVOKE privileges to/from yourself

SQL> revoke insert on tab1 from 'user1' @ 'user1';


revoke insert on tab1 from 'user1' @ 'user1'
*
ERROR at line 1:
ORA-00987: missing or invalid username(s)

SQL> revoke insert on tab1 from 'user1' 'user1';


revoke insert on tab1 from 'user1' 'user1'
*
ERROR at line 1:
ORA-00987: missing or invalid username(s)

SQL> drop table tab1;

Table dropped.

SQL> select *from tab1;


select *from tab1
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> drop user user1;


drop user user1
*
ERROR at line 1:
ORA-01031: insufficient privileges

SQL> connect
Enter user-name: student29
Enter password:
Connected.
SQL> drop user user1 cascade;

User dropped.

SQL> connect
Enter user-name: user1
Enter password:
ERROR:
ORA-01017: invalid username/password; logon denied

Warning: You are no longer connected to ORACLE.


SQL> desc tab1;
SP2-0640: Not connected
SP2-0641: "DESCRIBE" requires connection to server
SQL> connect
Enter user-name: student29
Enter password:
Connected.
SQL> desc tab1;
Name Null? Type
----------------------------------------- -------- ----------------------------
RN NUMBER(38)
SNO NUMBER(38)
NAME VARCHAR2(20)
DEPT VARCHAR2(20)

SQL> select *from tab1;

no rows selected

SQL> insert into tab1('&rn','&sno','&name','dept');


Enter value for rn: 1
Enter value for sno: 12
Enter value for name: agfyu
old 1: insert into tab1('&rn','&sno','&name','dept')
new 1: insert into tab1('1','12','agfyu','dept')
insert into tab1('1','12','agfyu','dept')
*
ERROR at line 1:
ORA-00928: missing SELECT keyword

SQL> insert into tab1('&rn','&sno','&name','&dept');


Enter value for rn: 1
Enter value for sno: 12
Enter value for name: shj
Enter value for dept: rg
old 1: insert into tab1('&rn','&sno','&name','&dept')
new 1: insert into tab1('1','12','shj','rg')
insert into tab1('1','12','shj','rg')
*
ERROR at line 1:
ORA-00928: missing SELECT keyword

SQL> insert into tab1 values('&rn','&sno','&name','&dept');


Enter value for rn: 1
Enter value for sno: 12
Enter value for name: thrj
Enter value for dept: srt
old 1: insert into tab1 values('&rn','&sno','&name','&dept')
new 1: insert into tab1 values('1','12','thrj','srt')

1 row created.

SQL> create view v1 as select *from tab1;

View created.

SQL> select *from v1;


RN SNO NAME DEPT
---------- ---------- -------------------- --------------------
1 12 thrj srt

SQL> insert into tab1 values('&rn','&sno','&name','&dept');


Enter value for rn: 2
Enter value for sno: 34
Enter value for name: awjg
Enter value for dept: teyhe
old 1: insert into tab1 values('&rn','&sno','&name','&dept')
new 1: insert into tab1 values('2','34','awjg','teyhe')

1 row created.

SQL> select *from all_users;

USERNAME USER_ID CREATED


------------------------------ ---------- ---------
USER29 37 18-MAR-24
STUDENT29 36 18-MAR-24
FLOWS_020100 35 07-FEB-06
FLOWS_FILES 34 07-FEB-06
HR 33 07-FEB-06
MDSYS 32 07-FEB-06
ANONYMOUS 28 07-FEB-06
XDB 27 07-FEB-06
CTXSYS 25 07-FEB-06
DBSNMP 23 07-FEB-06
TSMSYS 20 07-FEB-06

USERNAME USER_ID CREATED


------------------------------ ---------- ---------
DIP 18 07-FEB-06
OUTLN 11 07-FEB-06
SYSTEM 5 07-FEB-06
SYS 0 07-FEB-06

15 rows selected.

SQL> insert into tab1 values('&rn','&sno','&name','&dept');


Enter value for rn: 3
Enter value for sno: 66
Enter value for name: agf
Enter value for dept: sgh
old 1: insert into tab1 values('&rn','&sno','&name','&dept')
new 1: insert into tab1 values('3','66','agf','sgh')

1 row created.

SQL> /
Enter value for rn: 22
Enter value for sno: 89
Enter value for name: fhjy
Enter value for dept: arehj
old 1: insert into tab1 values('&rn','&sno','&name','&dept')
new 1: insert into tab1 values('22','89','fhjy','arehj')

1 row created.
SQL> select *from v1;

RN SNO NAME DEPT


---------- ---------- -------------------- --------------------
1 12 thrj srt
2 34 awjg teyhe
3 66 agf sgh
22 89 fhjy arehj

SQL> create or replace view v1 as select sno from tab1;

View created.

SQL> select *from v1;

SNO
----------
12
34
66
89

SQL> create or replace view v2 as select sno,name from tab1;

View created.

SQL> select *from v2;

SNO NAME
---------- --------------------
12 thrj
34 awjg
66 agf
89 fhjy

SQL> insert view v2 as select dept from tab1;


insert view v2 as select dept from tab1
*
ERROR at line 1:
ORA-00925: missing INTO keyword

SQL> insert into view v2 as select dept from tab1;


insert into view v2 as select dept from tab1
*
ERROR at line 1:
ORA-00903: invalid table name

SQL> insert into view v2 dept values('&sno','&name');


Enter value for sno: 11
Enter value for name: uifj
old 1: insert into view v2 dept values('&sno','&name')
new 1: insert into view v2 dept values('11','uifj')
insert into view v2 dept values('11','uifj')
*
ERROR at line 1:
ORA-00903: invalid table name
SQL> insert into tab1dept values('&sno','&name');
Enter value for sno: 11
Enter value for name: jkiudf
old 1: insert into tab1dept values('&sno','&name')
new 1: insert into tab1dept values('11','jkiudf')
insert into tab1dept values('11','jkiudf')
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> insert into tab1 dept values('&sno','&name');


Enter value for sno: 11
Enter value for name: hyuj
old 1: insert into tab1 dept values('&sno','&name')
new 1: insert into tab1 dept values('11','hyuj')
insert into tab1 dept values('11','hyuj')
*
ERROR at line 1:
ORA-00947: not enough values

SQL> insert into v2 values('&sno','&name');


Enter value for sno: 11
Enter value for name: ytght
old 1: insert into v2 values('&sno','&name')
new 1: insert into v2 values('11','ytght')

1 row created.

SQL> select *from v2;

SNO NAME
---------- --------------------
12 thrj
34 awjg
66 agf
89 fhjy
11 ytght

SQL> delete v2 from tab1 where sno=11;


delete v2 from tab1 where sno=11
*
ERROR at line 1:
ORA-00933: SQL command not properly ended

SQL> delete from v2 where sno=11;

1 row deleted.

SQL> select *from v2;

SNO NAME
---------- --------------------
12 thrj
34 awjg
66 agf
89 fhjy

SQL> update v1 set name='varsha' where dept=srt;


update v1 set name='varsha' where dept=srt
*
ERROR at line 1:
ORA-00904: "SRT": invalid identifier

SQL> update v1 set name='varsha' where dept='srt';


update v1 set name='varsha' where dept='srt'
*
ERROR at line 1:
ORA-00904: "DEPT": invalid identifier

SQL> update v1 set name='varsha' where sno=12;


update v1 set name='varsha' where sno=12
*
ERROR at line 1:
ORA-00904: "NAME": invalid identifier

SQL> select *from v1;

SNO
----------
12
34
66
89

SQL> update v2 set name='varsha' where sno=12;

1 row updated.

SQL> select *from v2;

SNO NAME
---------- --------------------
12 varsha
34 awjg
66 agf
89 fhjy

SQL> drop view v1;

View dropped.

SQL> select *from v1;


select *from v1
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> create index in_name on tab1(name);

Index created.
SQL> select *from tab1;

RN SNO NAME DEPT


---------- ---------- -------------------- --------------------
1 12 varsha srt
2 34 awjg teyhe
3 66 agf sgh
22 89 fhjy arehj

SQL> select name from tab1;

NAME
--------------------
varsha
awjg
agf
fhjy

SQL> show index from tab1;


SP2-0158: unknown SHOW option "index"
SP2-0158: unknown SHOW option "from"
tab ON
SP2-0158: unknown SHOW option "1"
SQL> drop index in_name on tab1;
drop index in_name on tab1
*
ERROR at line 1:
ORA-00933: SQL command not properly ended

SQL> drop index in_name on tab1(name);


drop index in_name on tab1(name)
*
ERROR at line 1:
ORA-00933: SQL command not properly ended

SQL> start transcation


SP2-0310: unable to open file "transcation.sql"
SQL> explain select name,dept from tab1 where dept='srt';
explain select name,dept from tab1 where dept='srt'
*
ERROR at line 1:
ORA-00905: missing keyword

SQL>

You might also like