0% found this document useful (0 votes)
3 views

DBMS LAB

The document outlines a program to design and implement a database with a focus on executing at least 10 different DML queries. It includes steps for creating tables, inserting records, and performing various queries such as filtering by salary, ordering by hire date, updating records, and using wildcards with the LIKE operator. Additionally, it provides SQL commands for each task, demonstrating the use of Boolean and arithmetic operators.

Uploaded by

Prasanna Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

DBMS LAB

The document outlines a program to design and implement a database with a focus on executing at least 10 different DML queries. It includes steps for creating tables, inserting records, and performing various queries such as filtering by salary, ordering by hire date, updating records, and using wildcards with the LIKE operator. Additionally, it provides SQL commands for each task, demonstrating the use of Boolean and arithmetic operators.

Uploaded by

Prasanna Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Program No:2

------------------------------------------------------------------------------------------------------
Title: Design and implement a database and apply at least 10 different DML queries
for the following task. For a given input string display only those records which
match the given pattern or a phrase in the search string. Make use of wild characters
and LIKE operator for the same. Make use of Boolean and arithmetic operators
wherever necessary.
-------------------------------------------------------------------------------------------------------
1. Create table emp with attributes EMP_ID integer, ENAME varchar (15), JOB
varchar (15), HIREDATE DATE, SAL integer (10), COMM integer (10),
DEPT_NO integer (15).

CREATE TABLE emp_chk (EMP_ID integer, ENAME varchar (15), JOB


varchar (15), HIREDATE DATE, SAL integer, COMM integer, DEPT_NO
integer);

2. Insert the records into the EMP table and display all the records of the emp
table.

insert into table_name ( Column_name1,Column_name1..column_name_n)


values (‘value1','value2',value3);
select * from table_name;
3. Create another table emp1 with all the attributes of emp table and insert all the
records of emp table into emp1 table at a time

CREATE table new_tablename LIKE old_tablename;


Select * from new_tablename; (Schema is created for the table)

INSERT INTO DB.new_tablename SELECT * FROM DB.old_tablename;


(Values of original table gets inserted to new created table)

(Multiple values insertion to the DB)


INSERT INTO sql_workbench.emp_chk (EMP_ID , ENAME, JOB, HIREDATE
, SAL , COMM , DEPT_NO ) values
(0002, 'Aditya','Supervisor','2000-10-12',2000,6,5),
(0003, 'Srihanth','Worker','2012-02-02',5000,8,2),
(0004, 'Sathya','Emp1','2019-10-12',1000,1,8);

4. Display all the information of emp table whose salary is greater than 2000

SELECT * FROM DB.Table_name WHERE SAL>2000;

5. Display distinct salary from emp table

SELECT DISTINCT SAL FROM DB.Table_name;


6. Display the record of emp table in ascending order of hire date.

SELECT * FROM DB.tablename ORDER BY HIREDATE asc;

7. Display the record of emp table in decreasing order of hire date.

SELECT * FROM DB.tablename ORDER BY HIREDATE desc;

8. Update the salary of employee to 5000 whose employee id is 7839


ALTER TABLE emp_chk
ADD PRIMARY KEY (EMP_ID);
//Above statements are required if we get error saying:
[Code: 1175. You are using safe update mode and you tried to update a table
without a WHERE that uses a KEY column. To disable safe mode, toggle the
option in Preferences -> SQL Editor and reconnect.]

update emp_chk set SAL = 5000 where EMP_ID = 5;

Another solution for the above-mentioned problem is:


SET SQL_SAFE_UPDATES = 0;
update emp_chk set SAL = 3000 where EMP_ID = 5;
SET SQL_SAFE_UPDATES = 1;

9. Delete the record of employee whose employee id is 7369


delete from emp_chk where EMP_ID = 5;

10. Display the salary of employee whose salary is in the range of 2000 to 5000.
SELECT * FROM emp_chk WHERE SAL BETWEEN 2000 AND 5000;

11.Display the records of employee whose jobs are 'Manager', 'Supervisor'and


Worker
SELECT * FROM emp_chk WHERE JOB IN ('Manager', 'Supervisor',
Worker);

12.Display name of employee whose name starts with A.


SELECT * FROM emp_chk WHERE ENAME LIKE 'A%';

Display name of employee whose name starts with A or S


SELECT * FROM emp_chk WHERE ENAME LIKE 'A%' or ENAME LIKE 'S
%';

13.Display the name of employees whose name does not start with A.
SELECT * FROM emp_chk WHERE ENAME NOT LIKE 'A%';

You might also like