You are on page 1of 46

PRATICAL-1

CREATE STUDENT TABLE TO DEMONSTRATE DDL COMMANDS

SQL> create table student(srollno number(10),sname varchar2(20),marks number(10),class


varchar2(10),address varchar2(10));

Table created.

SQL> insert into student values(1,'rajesh',550,'BSC','PORANKI');

1 row created.

SQL> insert into student values(2,'rakesh',450,'BSC','KANKIPADU');

1 row created.

SQL> insert into student values(3,'ramesh',500,'BSC','VUYYURU');

1 row created.

SQL> select * from student;

SROLLNO SNAME MARKS CLASS ADDRESS

---------- -------------------- ---------- ---------- ----------

1 rajesh 550 BSC PORANKI

2 rakesh 450 BSC KANKIPADU

3 ramesh 500 BSC VUYYURU

Page | 1
SQL> alter table student add(pincode number(10));

Table altered.

SQL> select * from student;

SROLLNO SNAME MARKS CLASS ADDRESS PINCODE

---------- -------------------- ---------- ---------- ---------- ----------

1 rajesh 550 BSC PORANKI

2 rakesh 450 BSC KANKIPADU

3 ramesh 500 BSC VUYYURU

SQL> rename student to studentdetails;

Table renamed.

SQL> select * from studentdetails;

SROLLNO SNAME MARKS CLASS ADDRESS PINCODE

---------- -------------------- ---------- ---------- ---------- ----------

1 rajesh 550 BSC PORANKI 521151

2 rakesh 450 BSC KANKIPADU 522151

3 ramesh 500 BSC VUYYURU 523151

SQL> truncate table studentdetails;

Page | 2
Table truncated.

SQL> select * from studentdetails;

no rows selected

SQL> drop table studentdetails;

Table dropped.

SQL> select * from studentdetails;

select * from studentdetails

ERROR at line 1:

ORA-00942: table or view does not exist

Page | 3
PRATICAL-2

CREATE STUDENT TABLE TO DEMONSTRATE DML COMMANDS

create a table in oracle with tablename student and attributes srollno,sname,marks,class,address.

SQL> create table student (srollno number(10),sname varchar2(10),marks number(3),class


varchar2(10),address varchar2(20));

Table created.

insert 5 records into the table student

SQL> insert into student values(11,'ramakrishna',200,'bsc','poranki');

1 row created.

SQL> insert into student values(12,'rama',300,'bsc','eluru');

1 row created.

SQL> insert into student values(13,'pavan',300,'bsc','eluru');

Page | 4
1 row created.

SQL> insert into student values(14,'vijay',400,'bsc','kankipadu');

1 row created.

SQL> insert into student values(15,'murali',100,'bsc','patamata');

1 row created.

retrieve all the data from student table

SQL> select * from student;

SROLLNO SNAME MARKS CLASS ADDRESS

---------- -------------------- ---------- ---------- --------------------

11 ramakrishna 200 bsc poranki

12 rama 300 bsc eluru

13 pavan 300 bsc eluru

14 vijay 400 bsc kankipadu

15 murali 100 bsc patamata

retrieving records from table student who are coming from eluru

SQL> select * from student where address='eluru';

SROLLNO SNAME MARKS CLASS ADDRESS

Page | 5
---------- -------------------- ---------- ---------- --------------------

12 rama 300 bsc eluru

13 pavan 300 bsc eluru

display the srollno and sname from student who are from class ‘bsc’

SQL> select srollno,sname from student where class='bsc';

SROLLNO SNAME

---------- --------------------

11 ramakrishna

12 rama

13 pavan

14 vijay

15 murali

display the srollno from student who are from address ‘eluru’

SQL> select srollno from student where address='eluru';

SROLLNO

----------

12

13

Page | 6
display the details of student whose marks >= 300

SQL> select * from student where marks>=300;

SROLLNO SNAME MARKS CLASS ADDRESS


---------- -------------------- ---------- ---------- --------------------
12 rama 300 bsc eluru
13 pavan 300 bsc eluru
14 vijay 400 bsc kankipadu

display the srollno and sname from student whose marks < 300

SQL> select srollno,sname from student where marks<300;

SROLLNO SNAME

---------- --------------------

11 ramakrishna

15 murali

replace marks of all students by 200

SQL> update student set marks=200;

5 rows updated.

SQL> select * from student;

SROLLNO SNAME MARKS CLASS ADDRESS

---------- -------------------- ---------- ---------- --------------------

Page | 7
11 ramakrishna 200 bsc poranki

12 rama 200 bsc eluru

13 pavan 200 bsc eluru

14 vijay 200 bsc kankipadu

15 murali 200 bsc patamata

change the marks of sname vijay to 400

SQL> update student set marks=400 where sname='vijay';

1 row updated.

SQL> select * from student;

SROLLNO SNAME MARKS CLASS ADDRESS

---------- -------------------- ---------- ---------- --------------------

11 ramakrishna 200 bsc eluru

12 rama 200 bsc eluru

13 pavan 200 bsc eluru

14 vijay 400 bsc kankipadu

15 murali 200 bsc patamata

increase the marks of all students by 200

SQL> update student set marks=marks+200;

5 rows updated.

SQL> select * from student;

Page | 8
SROLLNO SNAME MARKS CLASS ADDRESS

---------- -------------------- ---------- ---------- --------------------

11 ramakrishna 400 bsc poranki

12 rama 400 bsc eluru

13 pavan 400 bsc eluru

14 vijay 600 bsc kankipadu

15 murali 400 bsc patamata

delete the information of student vijay

SQL> delete from student where sname='vijay';

1 row deleted.

SQL> select * from student;

SROLLNO SNAME MARKS CLASS ADDRESS

---------- -------------------- ---------- ---------- --------------------

11 ramakrishna 400 bsc poranki

12 rama 400 bsc eluru

13 pavan 400 bsc eluru

15 murali 400 bsc patamata

rename the table student as std

SQL> rename student to std;

Table renamed.

Page | 9
SQL> select * from std;

SROLLNO SNAME MARKS CLASS ADDRESS

---------- -------------------- ---------- ---------- --------------------

11 ramakrishna 400 bsc poranki

12 rama 400 bsc eluru

13 pavan 400 bsc eluru

15 murali 400 bsc patamata

SQL> desc std;

Name Null? Type

----------------------------------------- -------- ----------------------------

SROLLNO NUMBER(10)

SNAME VARCHAR2(20)

MARKS NUMBER(3)

CLASS VARCHAR2(10)

ADDRESS VARCHAR2(20)

modifying the datatype and its size for existing table

SQL> alter table std modify(srollno number(20));

Table altered.

SQL> desc std;

Name Null? Type

----------------------------------------- -------- ----------------------------

Page | 10
SROLLNO NUMBER(20)

SNAME VARCHAR2(20)

MARKS NUMBER(3)

CLASS VARCHAR2(10)

ADDRESS VARCHAR2(20)

PRATICAL-3

CREATE A CUSTOMER TABLE TO DEMONSTRATE CONSTRAINTS IN SQL

Check Constraints have the specific condition for each row of the table.

 NOT NULL - Ensures that a column cannot have a NULL value .NOT accept NULL
values.
 UNIQUE - Ensures that all values in a column are different
 PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each
row in a table
 FOREIGN KEY - Prevents actions that would destroy links between tables
 CHECK - Ensures that the values in a column satisfies a specific condition
 DEFAULT - Sets a default value for a column if no value is specified
 CREATE INDEX - Used to create and retrieve data from the database very quickly

However, you can have many UNIQUE constraints per table, but only one PRIMARY
KEY constraint per table.

Relation

Page | 11
CREATE TABLE supplier
( supplier_id numeric(10) not null,
supplier_name varchar2(50) not null,
contact_name varchar2(50),
CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)
);

CREATE TABLE products


( product_id numeric(10) not null,
supplier_id numeric(10) not null,
CONSTRAINT fk_supplier
FOREIGN KEY (supplier_id)
REFERENCES supplier(supplier_id)
);

ALIASES
This Oracle tutorial explains how to use Oracle ALIASES (temporary names for columns or tables)
with syntax and examples.

Page | 12
Using an ALTER TABLE statement
The syntax for creating a check constraint in an ALTER TABLE statement in Oracle is:
ALTER TABLE table_name
ADD CONSTRAINT constraint_name CHECK (column_name condition) [DISABLE];

Disable a Check Constraint


The syntax for disabling a check constraint in Oracle is:
ALTER TABLE table_name
DISABLE CONSTRAINT constraint_name;

Enable a Check Constraint


The syntax for enabling a check constraint in Oracle is:
ALTER TABLE table_name
ENABLE CONSTRAINT constraint_name;

create a table with tablename customers with following fields and constraints

1)customer number must start with c and should not repeat and should not be null

2)customer name should not be null

3)deposit number should contain unique value

4) address should not be null and it must be from poranki,patamata,mogulrajpuram

SQL> create table customers

(cno varchar2(10) primary key,

cname varchar2(20) not null ,

deposit number(10) unique,

address varchar2(20) not null,

Page | 13
check(address in('poranki','patamata','mogulrajpuram')),

check(cno like 'c%'));

Table created.

CREATE TABLE product


( product_id numeric(10) not null,
supplier_name varchar2(50) not null,
customers_num varchar2(50),
CONSTRAINT fk_ product_customers
FOREIGN KEY (customers_num)
REFERENCES customers(cno));

SQL> desc customers;

Name Null? Type

----------------------------------------- -------- ----------------------------

CNO NOT NULL VARCHAR2(10)

CNAME VARCHAR2(20)

DEPOSIT NUMBER(10)

ADDRESS NOT NULL VARCHAR2(20)

SQL> insert into customers values('c101','rajesh',50000,'bhavanipuram');

insert into customers values('c101','rajesh',50000,'bhavanipuram')

ERROR at line 1:

ORA-02290: check constraint (SYSTEM.SYS_C007014) violated

Page | 14
SQL> insert into customers values('101','rajesh',50000,'poranki');

insert into customers values('101','rajesh',50000,'poranki')

ERROR at line 1:

ORA-02290: check constraint (SYSTEM.SYS_C007015) violated

SQL> insert into customers values('c101','rajesh',50000,'poranki');

1 row created.

SQL> insert into customers values('c102','rakesh',50000,'poranki');

insert into customers values('c102','rakesh',50000,'poranki')

ERROR at line 1:

ORA-00001: unique constraint (SYSTEM.SYS_C007017) violated

SQL> insert into customers values('c102','rakesh',60000,'poranki');

1 row created.

SQL> insert into customers values('','rakesh',60000,'poranki');

insert into customers values('','rakesh',60000,'poranki')

ERROR at line 1:

ORA-01400: cannot insert NULL into ("SYSTEM"."CUSTOMERS"."CNO")

Page | 15
SQL> insert into customers values('','rakesh',60000,'');

insert into customers values('','rakesh',60000,'')

ERROR at line 1:

ORA-01400: cannot insert NULL into ("SYSTEM"."CUSTOMERS"."CNO")

SQL> insert into customers values('c103','ramesh',70000,'patamata');

1 row created.

SQL> insert into customers values('c104','roshan',80000,'mogulrajpuram');

1 row created.

SELECT statement is used to retrieve records from one or more tables in an Oracle database

SQL> select * from customers;

CNO CNAME DEPOSIT ADDRESS

---------- -------------------- ---------- --------------------

c101 rajesh 50000 poranki

c102 rakesh 60000 poranki

c103 ramesh 70000 patamata

c104 roshan 80000 mogulrajpuram

The Oracle WHERE clause is used to filter the results from a SELECT, INSERT, UPDATE,
or DELETE statement.

Syntax

WHERE conditions;
Page | 16
Examples:
SELECT *
FROM customers
WHERE last_name = 'Anderson';

SELECT *
FROM suppliers
WHERE state = 'California'
AND supplier_id <= 750;

SELECT supplier_id
FROM suppliers
WHERE supplier_name = 'Apple'
OR supplier_name = 'Microsoft';

 GROUP BY Clause
The Oracle GROUP BY clause is used in a SELECT statement to collect data across multiple records and
group the results by one or more columns.

SELECT expression1, expression2, ... expression_n,   
aggregate_function (aggregate_expression)  
FROM tables  
WHERE conditions  
GROUP BY expression1, expression2, ... expression_n;  

Page | 17
SELECT item, SUM(sale) AS "Total sales"  
FROM salesdepartment  
GROUP BY item;  

PRATICAL-4

SQL STATEMENTS TO DEMONSTATE OPERATORS IN SQL

SQL> create table student(sno number(3),sname varchar2(20),class varchar2(10),totalmarks number(3));

Table created.

SQL> insert into student values(101,'anand','bsc',800);

Page | 18
1 row created.

SQL> insert into student values(102,'hari','bsc',900);

1 row created.

SQL> insert into student values(103,'govardhan','bca',950);

1 row created.

SQL> insert into student values(104,'krishna','bzc',700);

1 row created.

SQL> select * from student;

SNO SNAME CLASS TOTALMARKS

---------- -------------------- ---------- ----------

101 anand bsc 800

102 hari bsc 900

Page | 19
103 govardhan bca 950

104 krishna bzc 700

retrieve all information of the students whose names ends with character ‘a’

SQL> select * from student where sname like '%a';

SNO SNAME CLASS TOTALMARKS

---------- -------------------- ---------- ----------

104 krishna bzc 700

retrieve all information of the students whose names starts with character ‘a’

SQL> select * from student where sname like 'a%';

SNO SNAME CLASS TOTALMARKS

---------- -------------------- ---------- ----------

101 anand bsc 800

retrieve all information of the students whose second character is ‘a’

SQL> select * from student where sname like '_a%';

SNO SNAME CLASS TOTALMARKS

Page | 20
---------- -------------------- ---------- ----------

102 hari bsc 900

retrieve all information of the students whose names includes with character ‘a’

SQL> select * from student where sname like '%a%';

SNO SNAME CLASS TOTALMARKS

---------- -------------------- ---------- ----------

101 anand bsc 800

102 hari bsc 900

103 govardhan bca 950

104 krishna bzc 700

retrieve all information of the students of rollno either 103 or 104

SQL> select * from student where sno=103 or sno=104;

SNO SNAME CLASS TOTALMARKS

---------- -------------------- ---------- ----------

103 govardhan bca 950

104 krishna bzc 700

Page | 21
retrieve all information of the students according to their highest marks

SQL> select * from student order by totalmarks desc;

SNO SNAME CLASS TOTALMARKS

---------- -------------------- ---------- ----------

103 govardhan bca 950

102 hari bsc 900

101 anand bsc 800

104 krishna bzc 700

retrieve all sno’s of the students according to their highest marks

SQL> select sno from student order by totalmarks desc;

SNO

----------

103

102

101

104

retrieve all information of the students who are not from bca and bba

SQL> select * from student where class!='bca' and class!='bba';

SNO SNAME CLASS TOTALMARKS

---------- -------------------- ---------- ----------

101 anand bsc 800

102 hari bsc 900

Page | 22
104 krishna bzc 700

retrieve all information of the students where sno between 101 and 104

SQL> select * from student where sno between 101 and 104;

SNO SNAME CLASS TOTALMARKS

---------- -------------------- ---------- ----------

101 anand bsc 800

102 hari bsc 900

103 govardhan bca 950

104 krishna bzc 700

retrieve all information of the students where sno not between 103 and 104

SQL> select * from student where sno not between 103 and 104;

SNO SNAME CLASS TOTALMARKS

---------- -------------------- ---------- ----------

101 anand bsc 800

102 hari bsc 900

Page | 23
retrieve all information of the students who are from bzc and bsc classes

SQL> select * from student where class in('bsc','bzc');

SNO SNAME CLASS TOTALMARKS

---------- -------------------- ---------- ----------

101 anand bsc 800

102 hari bsc 900

104 krishna bzc 700

retrieve all information of the students with names rama,krishna , hari

SQL> select * from student where sname in('rama','krishna','hari');

SNO SNAME CLASS TOTALMARKS

---------- -------------------- ---------- ----------

102 hari bsc 900

104 krishna bzc 700

adding 20 marks to the students hari,Krishna.

SQL> update student set totalmarks=totalmarks+20 where sname='hari' or sname='krishna';

2 rows updated.

Page | 24
SQL> select * from student20;

SNO SNAME CLASS TOTALMARKS

---------- -------------------- ---------- ----------

101 anand bsc 800

102 hari bsc 920

103 govardhan bca 950

104 krishna bzc 720

PRATICAL-6

CREATE AN EMPLOYEE TABLE TO DEMONSTRATE AGGREGATE FUNCTIONS IN SQL

SQL> create table emp100(sno number(5),ename varchar2(20),experience number(3),s

alary number(6));

Table created.

SQL> insert into emp100 values(1,'rajesh',3,25000);

Page | 25
1 row created.

SQL> insert into emp100 values(2,'rakesh',4,30000);

1 row created.

SQL> insert into emp100 values(3,'ramesh',5,45000);

1 row created.

SQL> insert into emp100 values(4,'ravi',2,50000);

1 row created.

SQL> select * from emp100;

SNO ENAME EXPERIENCE SALARY

---------- -------------------- ---------- ----------

1 rajesh 3 25000

2 rakesh 4 30000

3 ramesh 5 45000

Page | 26
4 ravi 2 50000

SQL> select sum(salary) from emp100;

SUM(SALARY)

-----------

150000

SQL> select max(salary) from emp100;

MAX(SALARY)

-----------

50000

SQL> select min(salary) from emp100;

MIN(SALARY)

-----------

25000

SQL> select avg(salary) from emp100;

AVG(SALARY)

-----------

37500

Page | 27
SQL> select count(*) from emp100;

COUNT(*)

----------

PRATICAL-7

SQL STATEMENTS TO DEMONSTRATE STRING FUNCTIONS

SQL> select lower('DBMS') from dual;

LOWER

----

dbms

Page | 28
SQL> select upper('dbms') from dual;

UPPER

----

DBMS

SQL> select Initcap('dbms') from dual;

INIT

----

Dbms

SQL> select substr('database',3,5) from dual;

SUBST

-----

tabas

SQL> select length('database') from dual;

LENGTH('DATABASE')

------------------

SQL> select ltrim('database','da') from dual;

Page | 29
LTRIM

------

tabase

SQL> select rtrim('database','se') from dual;

RTRIM

------

databa

SQL> select lpad('data',10,'*') from dual;

LPAD('DATA’)

----------

******data

SQL> select rpad('data',10,'*') from dual;

RPAD('DATA’)

----------

data******

Page | 30
PRATICAL-8

SQL STATEMENTS TO DEMONSTRATE NUMERICAL FUNCTIONS

SQL> select abs(-10) from dual;

ABS(-10)

----------

Page | 31
10

SQL> select power(2,3) from dual;

POWER(2,3)

----------

SQL> select round(9.83456,2) from dual;

ROUND(9.83456,2)

----------------

9.83

SQL> select sqrt(9) from dual;

SQRT(9)

----------

PRATICAL-9

SQL STATEMENTS TO DEMONSTRATE DATE FUNCTIONS

SQL> select sysdate from dual;

SYSDATE

---------

Page | 32
28-JUL-18

SQL> select add_months(sysdate,4) from dual;

ADD_MONTH

---------

28-NOV-18

SQL> select last_day(sysdate) from dual;

LAST_DAY

---------

31-JUL-18

SQL> select months_between('02-may-17','02-jan-17') from dual;

MONTHS_BETWEEN('02-MAY-17','02-JAN-17')

---------------------------------------

SQL> select next_day(sysdate,'wednesday') from dual;

NEXT_DAY

---------

01-AUG-18

Page | 33
PRATICAL-10

SQL STATEMENTS TO DEMONSTRATE VIEWS

Views in SQL are kind of virtual tables.


A view also has rows and columns as they are in a real table in the database.
We can create a view by selecting fields from one or more tables present in the database.
A View can either have all the rows of a table or specific rows based on certain condition.

Page | 34
SQL> create table customer(cno number(10) primary key,cname varchar2(20),deposit number(10),address
varchar2(20));

Table created.

SQL> desc customer;

Name Null? Type

----------------------------------------- -------- ----------------------------

CNO NOT NULL VARCHAR2(10)

CNAME VARCHAR2(20)

DEPOSIT NUMBER(10)

ADDRESS VARCHAR2(20)

SQL> create view cust1 as select cno,cname from customer;

View created.

SQL> desc cust1;

Name Null? Type

----------------------------------------- -------- ----------------------------

CNO NOT NULL VARCHAR2(10)

CNAME VARCHAR2(20)

Page | 35
SQL> insert into cust1 values(11,'rajesh');

1 row created.

SQL> insert into cust1 values(12,'ramesh');

1 row created.

SQL> select * from cust1;

CNO CNAME

---------- --------------------

11 rajesh

12 ramesh

SQL> update cust1 set cno=13 where cname='ramesh';

1 row updated.

SQL> create view cust2 as select cno,cname from customer with read only;

View created.

Page | 36
SQL> insert into cust2 values(14,'rakesh');

insert into cust2 values(14,'rakesh')

ERROR at line 1:

ORA-01733: virtual column not allowed here

PRATICAL-11

CREATE TABLES TO DEMONSTRATE JOINS IN SQL

SQL> create table emp(eno number(10) primary key ,ename varchar2(10),salary number(6),deptno
number(10));

SQL> insert into emp values(101,'anand',15000,20);

SQL> insert into emp values(102,'adithya',12000,10);

SQL> insert into emp values(103,'balu',10000,20);


Page | 37
SQL> insert into emp values(104,'honey',15000,20);

SQL> insert into emp values(105,'sunny',18000,20);

SQL> insert into emp values(106,'abhilash',13000,30);

SQL> insert into emp values(107,'amit',16000,60);

SQL> insert into emp values(108,'amar',18000,70);

SQL> create table dept(deptno number(10) primary key ,location varchar2(20));

SQL> insert into dept values(10,’amaravathi’);

SQL> insert into dept values(20,’chennai’);

SQL> insert into dept values(30,’hyd’);

SQL> insert into dept values(40,’delhi’);

SQL> insert into dept values(50,’mumbai’);

SQL> SELECT * FROM EMP;

ENO ENAME SALARY DEPTNO


---------- ------------------------------ ---------- ----------
101 anand 15000 20
102 adithya 12000 10
103 balu 10000 20
104 honey 15000 20
105 sunny 18000 20
106 abhilash 13000 30
107 amit 16000 60
108 amar 18000 70

Page | 38
SQL> SELECT * FROM DEPT;

DEPTNO LOCATION
---------- --------------------
10 amaravathi
20 chennai
30 hyd
40 delhi
50 mumbai

SQL> SELECT * FROM EMP INNER JOIN DEPT ON EMP.DEPTNO=DEPT.DEPTNO;

ENO ENAME SALARY DEPTNO DEPTNO LOCATION


---------------------------------------------------------------------------------------------
101 anand 15000 20 20 chennai

102 adithya 12000 10 10 amaravathi

103 balu 10000 20 20 chennai

104 honey 15000 20 20 chennai

105 sunny 18000 20 20 chennai

106 abhilash 13000 30 30 hyd

SQL> SELECT * FROM EMP LEFT JOIN DEPT ON EMP.DEPTNO=DEPT.DEPTNO;

ENO ENAME SALARY DEPTNO DEPTNO LOCATION


--------------------------------------------------------------------------------------------------------------------
102 adithya 12000 10 10 amaravathi

105 sunny 18000 20 20 chennai

104 honey 15000 20 20 chennai

Page | 39
103 balu 10000 20 20 chennai

101 anand 15000 20 20 chennai

106 abhilash 13000 30 30 hyd

107 amit 16000 60

108 amar 18000 70

SQL> SELECT * FROM EMP RIGHT JOIN DEPT ON EMP.DEPTNO=DEPT.DEPTNO;

ENO ENAME SALARY DEPTNO DEPTNO LOCATION


--------------------------------------------------------------------------------------------------------------------
101 anand 15000 20 20 chennai

102 adithya 12000 10 10 amaravathi

103 balu 10000 20 20 chennai

104 honey 15000 20 20 chennai

105 sunny 18000 20 20 chennai

106 abhilash 13000 30 30 hyd

50 mumbai

40 delhi

SQL> SELECT * FROM EMP FULL JOIN DEPT ON EMP.DEPTNO=DEPT.DEPTNO;

ENO ENAME SALARY DEPTNO DEPTNO LOCATION


-------------------------------------------------------------------------------------------------------------------
101 anand 15000 20 20 chennai

102 adithya 12000 10 10 amaravathi

103 balu 10000 20 20 chennai

104 honey 15000 20 20 chennai


Page | 40
105 sunny 18000 20 20 chennai

106 abhilash 13000 30 30 hyd

107 amit 16000 60

108 amar 18000 70

50 mumbai

40 delhi

SQL> SELECT * FROM EMP NATURAL JOIN DEPT;

DEPTNO ENO ENAME SALARY LOCATION


-------------------------------------------------------------------------------------------------------------
20 101 anand 15000 chennai

10 102 adithya 12000 amaravathi

20 103 balu 10000 chennai

20 104 honey 15000 chennai

20 105 sunny 18000 chennai

30 106 abhilash 13000 hyd

Page | 41
Page | 42
What is DCL?
DCL (Data Control Language) includes commands like GRANT and REVOKE, which are
useful to give "rights & permissions." Other permission controls parameters of the database
system.

Examples of DCL commands:


Commands that come under DCL:

 Grant

Page | 43
 Revoke

Grant:
This command is use to give user access privileges to a database.

Syntax:

GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;

For example:

GRANT SELECT ON Users TO'Tom'@'localhost;

Revoke:
It is useful to back permissions from the user.

Syntax:

REVOKE privilege_nameON object_nameFROM {user_name |PUBLIC |role_name}

For example:

REVOKE SELECT, UPDATE ON student FROM BCA, MCA;

Page | 44
Page | 45
Page | 46

You might also like