You are on page 1of 3

THE INSTITUTE OF FINANCE MANAGEMENT (IFM)

FACULTY OF COMPUTING AND MATHEMATICS(FCM)


COMPUTER SCIENCE DEPARTMENT

BCS/ BIT
[ YEAR 2]

CSU/ITU 07314. DBMS


Practical#2 Intro. SQL, [13-17 NOV-2023]
Instructor: Siphy, A.S,
____________________________________________________
DATE FUNCTION: Task_1
---------------------------
DROP TABLE Person;

CREATE TABLE Person (


Id Integer PRIMARY KEY,
Name VARCHAR(20),
DoB DATE );
INSERT INTO Person(Id,Name,DoB)
VALUES (1,'Orlando','1-Jan-1972');
INSERT INTO Person(Id,Name,DoB)
VALUES (2,'Juane','1-Jan-1962');
INSERT INTO Person(Id,Name,DoB)
VALUES (3,'Venu','3-Feb-1972');
------------------------------------------------------------
TSK1_Example;
-->Get the age;
Opt1--->SQL
SELECT id,TRUNC(Months_between(current_date, dob)/12) AS Age
FROM Person;
Opt2--->SQL
SELECT id, ROUND(Months_between(Sysdate,dob)/12, 0) AS Age
FROM Person;
Q1:
Get id , name of the oldest person;
--------------------------------
DATE FUNCTION: Task_2
DROP TABLE Task_tbl;
CREATE TABLE Task _tbl(
TId Integer PRIMARY KEY,
Description VARCHAR(60),
DueDate DATE,
StartTime TIMESTAMP );
------------describe Task;
perform Full Insert!
INSERT INTO Task_tbl
VALUES (10,'Do something invaluable in your studies ',
'23-Oct-2023','01-Nov-2023 07:00:00 AM');
INSERT INTO Task_tbl
VALUES (20,'Do stuff after classes','18-Nov-2023','17-Nov-2023 03:00:00.20 PM');
INSERT INTO Task_tbl
VALUES(30,'Take Test One for DBMS in Dec', '18-Dec-2023',
'18-Dec-2023 09:00:00.00 AM')
----------------
Write SQL Query in each of the following natural queries
--------------------------------------------------------
Q1) Get all tasks which start on 01-Nov-2023
Q2) Get every task's id, description and duedate.
Q3) Get all tasks which are due on 18 Dec 2023.
Q4) Get the id and description of each task which are still on due date.
Q5) Display the day of the week when each employee was started.
( Include the id, description and startdate)
Q6) Calculate the difference in days between the current date and each Tak's due date.
---------------------------------------------------
Task_3: Working with Multiple Tables
---------------------------------------------------
CREATE Two Tables:
TSK3_TBL#1:DEPT_tbl(apply DROP table cmd if exists)
Description;
--->A 4 character department code which is the primary key.
--->Up to 40 characters for the department name.
--->Up to 60 characters for the department description.
//NOTE THAT, None of the fields should be allowed to contain NULLs//
TSK3_TBL#2:EMPL_tbl (apply DROP table cmd if exists)
Description;
--->A 6-digit employee number,calling it ESSN which is the primary key,
--->Up to 50 characters for the name, calling it EName.
--->Up to 11 digits for phone number, calling it EPhone.
--->A date of birth, calling it EDoB.
--->A date of employment, calling it EDoE.
--->Up to 9,999,999.99 for monthly wage (allowing for inflation!) calling it EWage.
--->Two characters for grade (can be CE, MD, MG, SE, JE), calling it EGrade.
//NOTE THAT, None of the fields should be allowed to contain nulls//
Q1.
Alter the employee table to add a 4-character department code,
which acts as a foreign key, to implement a relationship with the DEPT table
// apply ON DELETE CASCADE//
Q2.
Add the following information to the department table;
-Department 'COMP' is called the ‘Computer Science Department’
and is described as ‘Computing and ICT’.
-----------------------------------------------------------------------------------
-Add the following information to the employee table;
-Jeremy Moore, (employee number 111213), works in the sales department.
He was born on 24th May 2000 and started employment here on 10/10/2018.
-He is a senior designer (MD) who earns $4000 per month.
His phone number is 0915684111.
// Add at least six more records in each table by yourselves//
Write SQL Query in each of the following natural queries
--------------------------------------------------------------------------------------
Q3
Return a string showing the words 'You can contact ', the employee name and
' by phone at ', followed by the employee's phone number,
ending with a full stop ('.').
An example would be: You can contact Jeremy Moore at 0915684111.
Q4
Display each employee's employee number, name and their age in years
when they started to work here.
Q5
Display each employee's employee number, name and years of service - i.e.
the number of years they have worked here to date, and the amount of
money they earn per year.
Q6
Display the name and description of all departments that have no employees.
Q7
Display each grade and the monthly sum of money spent on that grade of
employee per month.
Q8
Display the employee number, name, grade and monthly wage for all
employees who earn more than the average wage.
------------------------------------------------------------------------------------------------------

You might also like