Sunteți pe pagina 1din 20

EX: NO: 1(a) CREATION OF A DATABASE AND WRITING SQL QUERIES TO

RETRIEVE INFORMATION FROM THE DATABASE


AIM:
To create a database and retrieve information from the database using SQL queries.

DDL COMMANDS:
DDL (Data Definition Language) statements are used to create, change the objects of a database.
Typically a database administrator is responsible for using DDL statements or production databases
in a large database system. The commands used are:
 Create - It is used to create a table.
 Alter - This command is used to add a new column, modify the existing column definition and
to include or drop integrity constraint.
 Drop - It will delete the table structure provided the table should be empty.
 Truncate - If there is no further use of records stored in a table and the structure has to be
retained, and then the records alone can be deleted.
 Desc - This is used to view the structure of the table.

SYNTAX: CREATE TABLE:


create table <table name> (fieldname-1 data type constraints if any, fieldname-2 data type
constraints if any,……. fieldname-n data type constraints if any);

ALTER TABLE:
 alter table <table name> add/modify (fieldname-1 datatype, fieldname-2 data type,…..
fieldname-n data type );
 alter table drop column column name;

DESCRIBING TABLE:
desc<table name>;

CHANGING NAME OF AN OBJECT:


To change the name of a table, view, sequence, or synonym, execute the rename statement. Syntax:
rename old name to new name;

TRUNCATE:
The truncate table statement
● removes all rows from a table
● Release the storage space used by that table
Syntax: truncate table <table name>;

DROP TABLE:
1. All data and structure in the table is deleted
2. Any pending transactions are committed.
3. All indexes are dropped.
Syntax: drop table <table name>; Table dropped.
SAMPLE OUTPUT:
SQL> create table student (sno number (2), regno number (12), name varchar2 (10), age number
(2), marks number (2));
Table created.
SQL>desc student;
Name Null? Type
-------------------- ---------------------- --------------------------
SNO NUMBER (2)
REGNO NUMBER (12)
NAME VARCHAR2 (10)
AGE NUMBER (2)
MARKS NUMBER (2)

SQL> alter table student add (total number (3));


Table altered.

SQL>desc student;
Name Null? Type
-------------------- --------------------- --------------------
SNO NUMBER (2)
REGNO NUMBER (12)
NAME VARCHAR2 (10)
AGE NUMBER (2)
MARKS NUMBER (2)
TOTAL NUMBER (3)

SQL> create table student_copy as select * from student;


Table created.

SQL> truncate table student;


Table truncated.

SQL>rename student_copy to table1;


Table renamed.

SQL> drop table table1;


Table dropped.
EXERCISES

1. Create a table of name employee having fields eno and ename

SQL> create table employee (eno integer, ename varchar (10));

Table created.

SQL> desc employee;

Name Null? Type


------------------------ -------- --------
ENO NUMBER(38)
ENAME VARCHAR2(10)

SQL> create table emp_com(ename varchar(20),cname varchar(20),salary number(7,2),


j_date date);

Table created.

SQL> desc emp_com;

Name Null? Type


--------------------------- -------- -------
ENAME VARCHAR2(20)
CNAME VARCHAR2(20)
SALARY NUMBER(7,2)
J_DATE DATE

2. Add the field address of employee in the employee database.

SQL> alter table employee add (e_address varchar(30));

Table altered.

SQL> desc employee;

Name Null? Type


--------------------------- -------- -------
ENO NUMBER(38)
ENAME VARCHAR2(10)
E_ADDRESS VARCHAR2(30)

3. Modify the data type of field ename in the employee database.

SQL> alter table employee modify(ename varchar2(20));

Table altered.
SQL> desc employee;

Name Null? Type


--------------------------- -------- --------
ENO NUMBER(38)
ENAME VARCHAR2(20)
E_ADDRESS VARCHAR2(30)

4. Drop the table named employee.

SQL> drop table employee;

Table dropped.

SQL> desc employee;

ERROR:

ORA-04043: object employee does not exist

5. Truncate the table named emp_com.

SQL> Truncate table emp_com;

Table truncated.

SQL> desc emp_com;

Name Null? Type


--------------------------- -------- -------
ENAME VARCHAR2(20)
CNAME VARCHAR2(20)
SALARY NUMBER(7,2)
J_DATE DATE

SQL> select * from emp_com; no rows selected


6. Create an employee table having employee number, employee name, designation,
salary fields.

SQL>create table emp (empno number (4), ename varchar2 (10), designation varchar2 (10),
salary number (8,2));

Table created.

7. Display the column name and data type of the table employee.

SQL> desc emp;

Name Null? Type


---------------------------------- -------- ---------
EMPNO NUMBER(4)
ENAME VARCHAR2(10)
DESIGNATION VARCHAR2(10)
SALARY NUMBER(8,2)
8. Create a table from an existing table with all the fields.

SQL> create table emp1 as select * from emp;

Table created.

SQL> desc emp1

Name Null? Type


---------------------------------- -------- --------
EMPNO NUMBER(4)
ENAME VARCHAR2(10)
DESIGNATION VARCHAR2(10)
SALARY NUMBER(8,2)

9. Create a table from an existing table with selected fields


SQL> create table emp2 as select empno, ename from emp;

Table created.

SQL> desc emp2


Name Null? Type
---------------------------------- -------- --------
EMPNO NUMBER(4)
ENAME VARCHAR2(10)

10. Create a new table from an existing table without any record.

SQL> create table emp3 as select * from emp where 1>2;

Table created.

SQL> desc emp3;

Name Null? Type


---------------------------------- -------- --------
EMPNO NUMBER(4)
ENAME VARCHAR2(10)
DESIGNATION VARCHAR2(10)
SALARY NUMBER(8,2);
11. Alter the column empno number (4) to empno number (6) in the emp table.

SQL>alter table emp modify empno number (6);

Table altered.
SQL> desc emp;
Name Null? Type
----------------------------------- -------- --------
EMPNO NUMBER(6)
ENAME VARCHAR2(10)
DESIGNATION VARCHAR2(10)
SALARY NUMBER(8,2)
12. Alter the table, emp with multiple columns (EMPNO, ENAME.)
SQL>alter table emp modify (empno number (7), ename varchar2(12));

Table altered.

SQL> desc emp;


Name Null? Type
---------------------------------- -------- --------
EMPNO NUMBER(7)
ENAME VARCHAR2(12)
DESIGNATIO VARCHAR2(10)
SALARY NUMBER(8,2);

13. Add a new column, qualification to the emp table


SQL> alter table emp add qualification varchar2(6);

Table altered.
SQL> desc emp;
Name Null? Type
----------------------------------- -------- ---------
EMPNO NUMBER(7)
ENAME VARCHAR2(12)
DESIGNATION VARCHAR2(10)
SALARY NUMBER(8,2)
QUALIFICATION VARCHAR2(6)

14. Add multiple columns in to emp table and display it.


SQL>alter table emp add (dob date, doj date);

Table altered.

SQL> DESC EMP;


Name Null? Type
---------------------------------- -------- --------
EMPNO NUMBER(7)
ENAME VARCHAR2(12)
DESIGNATION VARCHAR2(10)
SALARY NUMBER(8,2)
QUALIFICATION VARCHAR2(6)
DOB DATE
DOJ DATE

15. Drop a column from an existing table emp and display it.

SQL> alter table emp drop column doj;

Table altered.
SQL> desc emp;

Name Null? Type


----------------------------------- -------- ---------
EMPNO NUMBER(7)
ENAME VARCHAR2(12)
DESIGNATION VARCHAR2(10)
SALARY NUMBER(8,2)
QUALIFICATION VARCHAR2(6)
DOB DATE

16. Drop multiple columns from emp table.

SQL> alter table emp drop (dob, qualification);


Table altered.

SQL> desc emp;


Name Null? Type
---------------------------------- -------- ----------
EMPNO NUMBER(7)
ENAME VARCHAR2(12)
DESIGNATION VARCHAR2(10)
SALARY NUMBER(8,2)

17. Rename the table emp to employee using alter command.

SQL> alter table emp rename emp to employee;

SQL> desc employee;


Name Null? Type
---------------------------------- -------- ---------
EMPNO NUMBER(7)
ENAME VARCHAR2(12)
DESIGNATION VARCHAR2(10)
SALARY NUMBER(8,2)

RESULT:
Thus the creation of a database and writing SQL queries to retrieve information from the database
was implemented.
Practice Exercises:
1. Create a table called EMP with the following structure.
Name Type
a. EMPNO NUMBER(6)
b. ENAME VARCHAR2(20)
c. JOB VARCHAR2(10)
d. DEPTNO NUMBER(3)
e. SAL NUMBER(7,2)
2. Allow NULL for all columns except ename and job.
3. Add a column experience to the emp table. Experience numeric null allowed.
4. Create a table using NOT NULL and VARCHAR constraints.
5. Create dept table with the following structure.
a. Name Type
----------- -----------
DEPTNO NUMBER(2)
DNAME VARCHAR2(10)
LOC VARCHAR2(10)

6. Drop a column experience to the emp table.


7. Truncate the emp table and drop the dept table
8. Alter a table for student mark list
9. Delete a table created for hospital management
10. Rename a table created for library management system.
11. Modify a table for payroll management system

Sample Viva Questions:

1. List the characteristics of database.


2. What is the purpose of a database?
3. What is a database?
4. What is DBMS?
5. What is a Database System?
EX: NO: 1(b) PERFORMING INSERTION, DELETION, MODIFYING, ALTERING,
UPDATING AND VIEWING RECORDS BASED ON CONDITIONS.

AIM:
To Perform Insertion, Deletion, Modifying, Altering, Updating and Viewing records based on
conditions in RDBMS.

DESCRIPTION:
Data Manipulation Language
DML commands are the most frequently used SQL commands and is used to query and manipulate
the existing database objects. Some of the commands are
1. Insert
2. Select
3. Update
4. Delete

SYNTAX :

INSERT:
This is used to add one or more rows to a table. The values are separated by commas and the data
types char and date are enclosed in apostrophes. The values must be entered in the same order as
they are defined.
Inserting a single row into a table:
insert into <table name> values(fieldvalue-1,fieldvalue-2,…,fieldvalue-n);

Inserting more than one record using a single insert command:


insert into <table name> values(&fieldname-1,&fieldname-2,…&fieldname-n);

SELECT:
It is used to retrieve information from the table. It is generally referred to as querying the table. We
can either display all columns in a table or only specify column from the table.
SELECT(att_list) FROM <table name> [WHERE <condition/expression>];

Retrieval of all columns from a table:


Select * from tablename; // This query selects all rows from the table.

Retrieval of specific columns from a table:


It retrieves the specified columns from the table.
Select column_name1, …..,column_namen from table name;

Select command with where clause:


To select specific rows from a table we include “where” clause in the select command. It can appear
only after the “from” clause.
Syntax: Select column_name1, …..,column_namen from table name where condition;

Select command with order by clause:


Syntax: Select column_name1, …..,column_namen from table name where condition order by
colmnname;
Select command to create a table: Syntax:
create table tablename as select * from existing_tablename;

Select command to insert records: Syntax: insert into tablename( select columns from
existing_tablename);

UPDATE:
It is used to alter the column values in a table. A single column may be updated or more than one
column could be updated.
update<table name> set (fieldname-1 = value, fieldname-2 = value,…,fieldname-n = value)
[WHERE <condition/expression>];

DELETE:
After inserting row in a table we can also delete them if required. The delete command consists of
afrom clause followed by an optional where clause.
delete from <table name> [where <condition/expression>];

SAMPLE OUTPUT:
INSERT, SELECT, UPDATE AND DELETE COMMANDS
SQL> create table person(pidint, lastname varchar2(10),firstnamevarchar(10), address
varchar2(20),age number);
Table created.

INSERTING A SINGLE ROW INTO A TABLE


SQL> insert into person values(1,'Prettina','Anne','Bangalore',14);
1 row created.

SQL> insert into person values(2,'Benitto','Anish','Trichy',24);


1 row created.

SQL> select * from person;


PID LASTNAME FIRSTNAME ADDRESS AGE
---------- ---------- ---------- -------------------- ----------
1 Prettina Anne Bangalore 14
2 Benitto Anish Trichy 24

INSERTING MORE THAN ONE ROW USING A SINGLE INSERT COMMAND


SQL> insert into person values(&pid,'&lastname','&firstname','&address',&age);
Enter value for pid: 3
Enter value for lastname: Raj
Enter value for firstname: Anita
Enter value for address: Chennai
Enter value for age: 27
old 1: insert into person values(&pid,'&lastname','&firstname','&address',&age)
new 1: insert into person values(3,'Raj','Anita','Chennai',27)
1 row created.
SQL> /
Enter value for pid: 4
Enter value for lastname: Kumar
Enter value for firstname: Ashok
Enter value for address: Coimbatore
Enter value for age: 30
old 1: insert into person values(&pid,'&lastname','&firstname','&address',&age)
new 1: insert into person values(4,'kumar','Ashok','Coimbatore',30)
1 row created.
SQL> select * from person;
PID LASTNAME FIRSTNAME ADDRESS AGE
---------- ---------- ---------- -------------------- ----------
1 Prettina Anne Bangalore 14
2 Benitto Anish Trichy 24
3 Raj Anita Chennai 27
4 Kumar Ashok Coimbatore 30

UPDATE VALUES USING CONDITION


SQL> update person set address='Coimbatore'where pid=2;
1 row updated.

SQL> select * from person;


PID LASTNAME FIRSTNAME ADDRESS AGE
---------- ---------- ---------- -------------------- ----------
1 Prettina Anne Bangalore 14
2 Benitto Anish Coimbatore 24
3 Raj Anita Chennai 27
4 Kumar Ashok Coimbatore 30

SELECT COMMAND USING 'WHERE' CLAUSE


SQL>select * from person where address='Coimbatore';
PID LASTNAME FIRSTNAME ADDRESS AGE
---------- ---------- ---------- -------------------- ----------
2 Benitto Anish Coimbatore 24
4 Kumar Ashok Coimbatore 30

SQL>select firstname, age from person where address='Coimbatore';


FIRSTNAME AGE
-------------------- ----------
Anish 24
Ashok 30

SQL>select * from person where lastname= 'Kumar' and address='Coimbatore';


PID LASTNAME FIRSTNAME ADDRESS AGE
---------- ---------- ---------- -------------------- ----------
4 Kumar Ashok Coimbatore 30
SELECT COMMAND WITH LIKE OPERATOR
SQL> select * from person where address like 'C%';
PID LASTNAME FIRSTNAME ADDRESS AGE
---------- ---------- ---------- -------------------- ----------
2 Benitto Anish Coimbatore 24
3 Raj Anita Chennai 27
4 Kumar Ashok Coimbatore 30

SQL> select * from person where address like '%n%';


PID LASTNAME FIRSTNAME ADDRESS AGE
---------- ---------- ---------- -------------------- ----------
1 Prettina Anne Bangalore 14
3 Raj Anita Chennai 27

SELECT COMMAND USING BETWEEN OPERATOR


SQL> select * from person where pid between 1 and 3;
PID LASTNAME FIRSTNAME ADDRESS AGE
---------- ---------- ---------- -------------------- ----------
1 Prettina Anne Bangalore 14
2 Benitto Anish Coimbatore 24
3 Raj Anita Chennai 27

SELECT COMMAND USING IN OPERATOR


SQL> select * from person where pidin(1,3);
PID LASTNAME FIRSTNAME ADDRESS AGE
---------- ---------- ---------- -------------------- ----------
1 Prettina Anne Bangalore 14
3 Raj Anita Chennai 27

SELECT COMMAND TO ELIMINATE DUPLICATES


SQL> select DISTINCT address from person;
ADDRESS
----------------
Bangalore
Coimbatore
Chennai

SELECT COMMAND WITH ORDER BY CLAUSE


SQL> select pid, lastname, age from person order by lastname;
PID LASTNAME AGE
---------- ---------- ----------
2 Benitto 24
4 Kumar 30
1 Prettina 14
3 Raj 27
SELECT COMMAND TO CREATE A TABLE
SQL> create table individual as select * from person;
Table created.

SQL> select * from individual;


PID LASTNAME FIRSTNAME ADDRESS AGE
---------- ---------- ---------- -------------------- ----------
1 Prettina Anne Bangalore 14
2 Benitto Anish Coimbatore 24
3 Raj Anita Chennai 27
4 Kumar Ashok Coimbatore 30

SELECT COMMAND WITH FUNCTIONS


SQL> select max(age) from person;
MAX(AGE)
----------
30

SQL> select sum(age) from person;


SUM(AGE)
----------
95

DELETE COMMAND
SQL> delete from person where pid=4;
1 row deleted.

SQL> select * from person;


PID LASTNAME FIRSTNAME ADDRESS AGE
---------- ---------- ---------- -------------------- ----------
1 Prettina Anne Bangalore 14
2 Benitto Anish Coimbatore 24
3 Raj Anita Chennai 27
EXERCISES
1. Insert the records in to employee database.
SQL>INSERT INTO EMP VALUES (101,'NAGARAJAN','LECTURER', 15000);
1 row created.

2. Display the records from employee.


SQL> SELECT * FROM EMP;
EMPNO ENAME DESIGNATION SALARY
---------- ------------ ------------------- ------------
101 NAGARAJAN LECTURER 15000

INSERT A RECORD USING SUBSITUTION METHOD


3. Insert the records in to employee using substitution method.
SQL> INSERT INTO EMP VALUES(&EMPNO,'&ENAME','&
DESIGNATION','&SALARY');
Enter value for empno: 102
Enter value for ename: SARAVANAN
Enter value for DESIGNATION: LECTURER
Enter value for salary: 15000
old 1: INSERT INTO EMP VALUES(&EMPNO,'&ENAME','&
DESIGNATION','&SALARY')
new 1: INSERT INTO EMP VALUES(102,'SARAVANAN','LECTURER','15000')
1 row created.

SQL> /
Enter value for empno: 103
Enter value for ename: PANNERSELVAM
Enter value for DESIGNATION: ASST. PROF
Enter value for salary: 20000
old 1: INSERT INTO EMP VALUES(&EMPNO,'&ENAME','&
DESIGNATION','&SALARY')
new 1: INSERT INTO EMP VALUES(103,'PANNERSELVAM','ASST.PROF','20000')
1 row created.

SQL> /
Enter value for empno: 104
Enter value for ename: CHINNI
Enter value for DESIGNATION: HOD, PROF
Enter value for salary: 45000
old 1: INSERT INTO EMP VALUES(&EMPNO,'&ENAME','&
DESIGNATION','&SALARY')
new 1: INSERT INTO EMP VALUES(104,'CHINNI','HOD, PROF','45000')
1 row created.
SQL> SELECT * FROM EMP;

EMPNO ENAME DESIGNATION SALARY


---------- ------------ ------------------- ------------
101 NAGARAJAN LECTURER 15000
102 SARAVANAN LECTURER 15000
103 PANNERSELVAM ASST.PROF 20000
104 CHINNI HOD,PROF 45000

4. Update the records from employee.


SQL> UPDATE EMP SET SALARY=16000 WHERE EMPNO=101;
1 row updated.

SQL> SELECT * FROM EMP;

EMPNO ENAME DESIGNATION SALARY


---------- ------------ ------------------- ------------
101 NAGARAJAN LECTURER 16000
102 SARAVANAN LECTURER 15000
103 PANNERSELVAM ASST.PROF 20000
104 CHINNI HOD,PROF 45000

UPDATE MULTIPLE COLUMNS


5. Update multiple records from employee.

SQL>UPDATE EMP SET SALARY = 16000, DESIGNATION='ASST. PROF' WHERE


EMPNO=102;
1 row updated.

SQL> SELECT * FROM EMP;


EMPNO ENAME DESIGNATION SALARY
---------- ------------ ------------------- ------------
101 NAGARAJAN LECTURER 16000
102 SARAVANAN ASST. PROF 16000
103 PANNERSELVAM ASST. PROF 20000
104 CHINNI HOD, PROF 45000

6. Delete records from employee.

SQL> DELETE EMP WHERE EMPNO=103;


1 row deleted.

SQL> SELECT * FROM EMP;

EMPNO ENAME DESIGNATION SALARY


---------- ------------ ------------------- ------------
101 NAGARAJAN LECTURER 16000
102 SARAVANAN ASST.PROF 16000
104 CHINNI HOD,PROF 45000
7. Insert the employee_ number(eno), employee _name(ename) and employee_address
(e_address) into the table employee.
SQL> insert into employee values(101,'Smith','chennai');
1 row created.

8. Inserting more number of records using substitution variables.


SQL> insert into employee values('&eno','&ename', '&e_address');
Enter value for eno: 222
Enter value for ename: john
Enter value for e_address: coimbatore
old 1: insert into employee values('&eno','&ename','&e_address')
new 1: insert into employee values('222','john','coimbatore')
1 row created.

SQL> /
Enter value for eno: 333
Enter value for ename: nithya
Enter value for e_address: bombay
old 1: insert into employee values('&eno','&ename','&e_address')
new 1: insert into employee values('333','nithya','bombay')
1 row created

SQL> select *from employee;


ENO ENAME E_ADDRESS
------ ----------- -----------------
101 Smith chennai
222 john coimbatore
333 nithya bombay

9. Inserting null values


SQL> insert into employee values(444,'raja',null);
1 row created.
SQL> insert into employee values(555,'ravi',null);
1 row created.
SQL> select * from employee;

ENO ENAME E_ADDRESS


------ ----------- -----------------
101 Smith chennai
222 john coimbatore
333 nithya bombay
444 raja
555 ravi

10. Insert the employee _name(ename) ,company_name(cname), salary and date of


joining (j_date) into the table emp_com.
SQL> insert into emp_com values('smith','TCS',5000,'17-may-2000');
1 row created.
SQL> insert into emp_com values('nithya','ACC',12000,'11-june-2002');
1 row created.

SQL> insert into emp_com values('john','TCS',7000,'12-july-2000');


1 row created.

SQL> insert into emp_com values('ravi','IBM',6000,'10-march-1999');


1 row created.

SQL> insert into emp_com values('raja','ACC',23000,'14-april-2000');


1 row created.

SQL> select * from emp_com;


ENAME CNAME SALARY J_DATE
----------- ----------- ------------ ----------------
smith TCS 5000 17-MAY-00
nithya ACC 12000 11-JUN-02
john TCS 7000 12-JUL-00
ravi IBM 6000 10-MAR-99
raja ACC 23000 14-APR-00

11. Change the address of smith as nagpur where eno=101.

SQL> update employee set e_address='nagpur' where eno=101;


1 row updated.

SQL> select * from employee;


ENO ENAME E_ADDRESS
------ ----------- -----------------
101 Smith chennai
222 john coimbatore
333 nithya bombay
444 raja
555 ravi

12. Set the address of raja as nagpur where eno=444.


SQL> update employee set e_address='nagpur' where eno=444;
1 row updated.
SQL> select * from employee;
ENO ENAME E_ADDRESS
------ ----------- -----------------
101 Smith chennai
222 john coimbatore
333 nithya bombay
444 raja nagpur
555 ravi
13. Set the address of ravi as chennai where eno=555.

SQL> update employee set e_address='chennai' where eno=555;


1 row updated.

SQL> select * from employee;


ENO ENAME E_ADDRESS
------ ----------- -----------------
101 Smith chennai
222 john coimbatore
333 nithya bombay
444 raja nagpur
555 ravi chennai

14. Increase the salary of employees by 20 percent where company is ‘ACC’.

SQL> update emp_com set salary=salary*0.2 where cname='ACC';


2 rows updated.

SQL> select * from emp_com;


ENAME CNAME SALARY J_DATE
----------- ----------- ------------ --------------
smith TCS 5000 17-MAY-00
nithya ACC 2400 11-JUN-02
john TCS 7000 12-JUL-00
ravi IBM 6000 10-MAR-99
raja ACC 4600 14-APR-00

15. Decrease the salary of john by 1500.


SQL> update emp_com set salary=salary-1500 where ename='john';
1 row updated.

SQL> select * from emp_com;


ENAME CNAME SALARY J_DATE
----------- ----------- ----------- --------------
smith TCS 5000 17-MAY-00
nithya ACC 2400 11-JUN-02
john TCS 5500 12-JUL-00
ravi IBM 6000 10-MAR-99
raja ACC 4600 14-APR-00

16. All employees of company ‘TCS’ having salary grater than 5000 are shifted to
TATA.

SQL> update emp_com set cname='TATA' where cname='TCS' and salary>5000;


1 row updated.

SQL> select * from emp_com;


ENAME CNAME SALARY J_DATE
----------- ----------- ----------- --------------
smith TCS 5000 17-MAY-00
nithya ACC 2400 11-JUN-02
john TATA 5500 12-JUL-00
ravi IBM 6000 10-MAR-99
raja ACC 4600 14-APR-00

17. Delete all the rows from the table employee having address ‘nagpur’

SQL> delete employee where e_address='nagpur';


2 rows deleted.

SQL> select * from employee;


ENO ENAME E_ADDRESS
--------- ------------ -----------------
222 john coimbatore
333 nithya bombay
555 ravi chennai

18. Delete all the rows from the table employee.

SQL> delete employee;


3 rows deleted.

SQL> delete employee;


0 rows deleted.

SQL> select * from employee; no rows selected

19. Delete rows of emp_com having salary greater than 5000.

SQL> delete emp_com where salary>6000;


0 rows deleted.

SQL> delete emp_com where salary>5000;


2 rows deleted.

SQL> select * from emp_com;


ENAME CNAME SALARY J_DATE
----------- ----------- ----------- --------------
smith TCS 5000 17-MAY-00
nithya ACC 2400 11-JUN-02
raja ACC 4600 14-APR-00

RESULT
Thus the Insertion, Deletion, Modifying, Altering, Updating and Viewing records based on
conditions in RDBMS were executed and verified.
Practice Exercise
1. Create the following tables with the mapping given below.
a. stu_details (reg_no, stu_name, address, city)
b. mark_details (reg_no, mark1, mark2, mark3, total)
(i). Display only those rows whose total ranges between 250 and 300.
(ii). Drop the table mark_details.
(iii). Delete the row whose reg_no=161.
(iv). Display all details whose names begins with 'a'.

2. Create the following tables with the mapping given below.


a. emp_details (emp_no, emp_name, address, mobile_no, dept_no, salary).
b. dept_details (dept_no, dept_name, location).
(i) Truncate the table dept_details.
(ii) Display the structure of the table emp_details.
(iii) Convert the first letter of emp_name into capitals.
(iv) Display the emp_namegetting highest salary.

3. Create the following tables with the mapping given below.


a. book (book_name,author,price,quantity).
b. customer (Cust_id, Cust_name, Addr, ph_no,pan_no)
(i) Truncate the table customer.
(ii) List the author of the book which one have the price of 200.
(iii).List the price of the book which one is between the price of 175 & 250.
(iv).Retrieve all the details from the table book whose author name start with K.

4. Create the following tables with the mapping given below.


a. stu_details (reg_no, stu_name, DOB, address, city)
b. mark_details (reg_no, mark1, mark2, mark3, total)
(i)Find out the name of all students.
(ii)List all the student detail that who are all located in Chennai.
(iii) Drop the table mark_details.

5. Create the following table with the mapping given below.


Customer (Cust_id, Cust_name, Addr, ph_no,pan_no).
(i)Delete the row where cust_name=’NANCY’.
(ii)Update the addr where cust_name=’MATHIK’.
(iii)Display the details of a customer named ‘LITHUANA’.

Sample Viva Questions

1. What are the categories of SQL command?


2. What is a query?
3. List DDL commands.
4. List DML commands.
5. List DCL commands.

S-ar putea să vă placă și