Database Management System Practical SQL

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 7

Database Management System

Practical SQL

SQL

SQL was invented by IBM in 1970 to get information into and out of relational database management system. SQL command divided into three categories:

DDL ( Data Definition language)-Create, Alter, Drop


DML ( Data Manipulation language)- Select, insert, update , delete DCL ( Data Control language)-grant, revoke

Create table employee( code number(5), Deptt char(10), name char(20), address varchar(30), DOB date);

Describe employee; ( Display table structure) Insert into employee values(101,abc,xyz,delhi,14-feb-2006);

insert into employee (code, deptt, name, address, dob) values(101,abc,xyz,delhi,14-feb-2006);

Insert into employee values (&code, '&deptt', '&name', &address', '&date');

Select Statement

Select code, name, salary from employee; select * from employee; select * from employee where salary >4000;

Select last_name, salary+300 from employee;


Select last_name, salary, 12*salary+100 from employee;

Select last_name, job_id from employee where last_name=abc;


Select last_name, salary from employee where salary between 2500 and 3500;

IN condition

To test for values in a specified set of values. Select emp_id, last_name, manager_id from employee where manager_id in ( 100,101,201);

Select emp_id, last_name, manager_id from employee where last_name in (sharma, verma);

Like condition

It is used when you dont know the exact value to search . % denotes many character _ denotes any single character. Select first_name from employee where first_name like S%; Note: It will return all rows whose first name began with S. name began with s will not returned. Select first_name , join_date from employee where join_date like %95; Note: It will return all rows whose join date between Jan 1995 and Dec 1995.

Select last_name from employee where last_name like _o% ; Result: Kochhar Lorentz Mourgos Null Conditions : Test for Null using Is null operator.

Select last_name, manager_id from employee where manager_id is null. Last_name Kamal Manager_id

You might also like