DBMS Practical 1-12
DBMS Practical 1-12
DBMS Practical 1-12
Output:
ii) Display employee’s complete details including employee_id, employee_name,
employee_department_no, employee_date_of_joining, employee_salary,
employee_email_id, and employee_contact_no.
Query:
SELECT * FROM uscs_employee;
Output:
iii) Display employee’s complete details including employee_id, employee_name,
employee_department_no, employee_date_of_joining, employee_salary,
employee_email_id, and employee_contact_no who work in department number 444.
Query:
SELECT * FROM uscs_employee WHERE employee_department_no LIKE '444';
Output:
iv) Display employee_id, employee_name, employee_date_of_joining who work in
department number 333.
Query:
SELECT employee_id, employee_name, employee_date_of_joining FROM uscs_employee WHERE
employee_department_no LIKE '333';
Output:
Output:
Output:
Practical 2: Implement DDL and DML on the uim_employee table. Consider the
following employee table:
Attribute Datatype Size
employee_id Varchar2 10
employee_name Char 25
employee_department_no Number 03
employee_date_of_joining Date -
employee_salary Number 8,2
employee_email_id Varchar2 30
employee_contact_no Number 12
Query:
CREATE TABLE uim_employee
(employee_id VARCHAR2(10), employee_name CHAR(25), employee_department_no NUMBER(3),
employee_date_of_joining DATE, employee_salary NUMBER(8,2), employee_email_id varchar2(30),
employee_contact_no NUMBER(12));
Output:
i) Add a new column named employee_address having data type as varchar2, size 30 in the
uim_employee table.
Query:
ALTER TABLE uim_employee
ADD employee_address VARCHAR2(30);
Output:
Output:
Output:
Output:
v) Rename the table to employee_details from the table name uim_employee.
Query:
ALTER TABLE uim_employee
RENAME TO employee_details;
Output:
Output:
Output:
Practical 3: Implement of keys and constraints concept. Create a table named
uim_student having attributes such as: student's roll number, student's name, student's date
of birth, student's course, student's house address, student's contact number, student's
aadhaar number. The attribute named: student_roll_no has a PRIMARY KEY constraint,
student_name has NOT NULL constraint, student_ aadhaar_no as UNIQUE constraint.
Consider the following table:
Query:
CREATE TABLE uim_student
(student_roll_no NUMBER(3), student_name CHAR(25), student_date_of_birth DATE, student_course
VARCHAR(15),
student_address VARCHAR2(30), student_contact_no NUMBER(10),
student_aadhaar_no NUMBER(12));
Output:
Output:
Output:
iv) Examine the error message by NOT inserting student_name value in a row in the table.
Write the error message and reason.
Query:
INSERT INTO uim_student
(student_roll_no,student_date_of_birth,student_course,student_address,student_contact_no,student_aadha
ar_no)
VALUES ("444","14-01-2004","BCA","DEHRADUN","9519842517", "654831486348");
Output:
v) Examine the error message by inserting same student aadhaar_no values for two rows.
Write the error message and reason
Query:
INSERT INTO uim_student
(student_roll_no,student_name,student_date_of_birth,student_course,student_address,student_contact_no,
student_aadhaar_no)
VALUES ("444","ADARSH","05-08-2002","BCA","PREMNAGAR","4985634814", "698488915351");
Output:
Practical 4: Implement of foreign key concept using two tables named: uscs_employee
and uscs_department. The employee has employee’s id, employee’s name, employee’s
department number. The department table has department name and department location.
Consider the following two table:
Output:
Output:
Query:
mysql> INSERT INTO uscs_department Values('101','BCA','USCS Building'); Query OK, 1
row affected (0.00 sec)
mysql> INSERT INTO uscs_department Values('102','BSc IT','USCS Building'); Query OK,
1 row affected (0.00 sec)
mysql> INSERT INTO uscs_department Values('103','MCA','USCS Building'); Query OK,
1 row affected (0.00 sec)
iv) Display the data of uscs_department table.
Query:
select * from uscs_department;
Output: -
v) Insert employee’s details working in the corresponding department as in the
uscs_department table.
Query:
mysql> INSERT INTO uscs_employee Values('111','Aman Yadav','101'); Query OK, 1
row affected (0.00 sec)
mysql> INSERT INTO uscs_employee Values('222','Kamal Singh','102'); Query OK, 1
row affected (0.00 sec)
mysql> INSERT INTO uscs_employee Values('333','Armaan Malik','103'); Query OK, 1
row affected (0.00 sec)
Output:
Query:
select * from uscs_employee;
Output:
viii) Delete any department number from uscs_department table and examine its effects
in uscs_employee table.
Query:
DELETE FROM uscs_department WHERE department_no = 103;
Output: -
Practical 5: Create a table named employee_contact_details from
employee table by taking the attribute named: employee_id.
Consider the table below:
Table name: employee_contact_details
Attribute Datatype Size
employee_id employee_id from employee table
Output:
Output:
Practical 6: Create a table named uscs_book having the attributes related
to book_id, book_name and book_theme attribute can have only two values:
BCA or MCA. Consider the table below:
Table name: uscs_book
Attribute Datatype Size Constraint
book_id Number 10 PRIMARY KEY
book_name Varchar2 25 NOT NULL
book_theme Char 4 CHECK
Output:
Output:
Output:
iv) Examine the error message by inserting a value other than IT/MGT in
column named book_theme. Write the error message and reason.
Query:
INSERT INTO uscs_book (book_id, book_name, book_theme)
VALUES (3, ‘Introduction to SQL Queries’, ‘MGMT’);
Output:
Practical 7: Extract the table from both the table by performing
join. Given two tables named: uscs_employee and uscs_department.
The employee table has attributes related to the employee’s id,
employee’s name and employee’s department number. The
department table has attributes related to the department number,
department name and department location. Consider the following
two tables:
Table name: uscs_employee
Attribute Datatype Size Constraint
employee_id Varchar2 8 -
employee_name Char 20 -
employee_department_n Number 3 FOREIGN KEY
o
Output:
Output:
Output:
Output:
Output:
Output:
Practical 8: The data in the table can be grouped based on certain
attributes. Consider the book table having attributes as book_id,
book_name, book_theme and book_price. Consider the table below:
Table name: uscs_book
Attribute Datatype Size Constraint
book_no Number 10 PRIMARY KEY
book_name Varchar2 25 NOT NULL
book_theme Char 4 CHECK
Note: the book_theme can either be 'cs' or 'it' only.
CREATE TABLE uscs_book (book_no NUMBER (10)
PRIMARY KEY, book_name VARCHAR2 (25) NOT NULL,
book_theme CHAR (4), CHECK (book_theme IN (‘CS’, ‘IT’));
i) Add a new column named book_price having data type as Number and
size as 7,2 in the exisiting table named uscs_book.
Query:
ALTER TABLE uscs_book
ADD book_price NUMBER (7,2);
Output:
Output:
UPDATE uscs_book
SET book_price = '720' WHERE book_id = '112';
UPDATE uscs_book
SET book_price = '570' WHERE book_id = '113';
Output:
Output:
v) Find the sum of all the book price based on the book theme.
Query:
SELECT MAX (book_price) FROM uscs_book
GROUP BY book_theme;
Output:
Output:
Practical 9: There are numerous aggregate functions that can be
performed on table(s). Consider the attributes in the employee table
as: employee’s id, employee’s name, employee’s department number,
employee’s Designation, employee’s date of joining, employee’s
salary, employee’s email id, employee’s contact no, employee’s
aadhaar number.
Table name: uu_employee
Attribute Datatyp Size Constraint
e
employee_id Varchar2 10 PRIMARY KEY
employee_name Char 25 NOT NULL
employee_department_no Number 03 NOT NULL
employee_designation Varchar2 15 NOT NULL
employee_date_of_joining Date - NOT NULL
employee_salary Number 8,2 NOT NULL
employee_email_id Varchar2 30 NOT NULL
employee_contact_no Number 12 NOT NULL
employee_aadhaar_no Number 12 UNIQUE
Output:
Output:
Output:
Practical 10: Demonstrate the following based on the
uu_employee table.
i) Count the number of employees in the uu_employee table.
Query:
SELECT COUNT (*) AS employee_count FROM uu_employee;
Output:
Output:
Output:
Output:
Output:
iv) Display the customer_ home_city in with first letter as capital and
remaining in lower case (e.g. Dehradun).
Query:
SELECT INITCAP (customer_ home_city) AS formatted_home_city FROM
uscs_customer;
Output:
Practical 12: Implement the date functions on uu_employee table.
Consider the attributes in the employee table as: employee’s id,
employee’s name, employee’s department number, employee’s
designation, employee’s date of joining, employee’s salary,
employee’s email id, employee’s contact no, employee’s aadhaar
number and employee’s date of resigning.
Table name: employee_table
Attribute Datatype Size Constraint
employee_id Varchar2 10 PRIMARY KEY
employee_name Char 25 NOT NULL
employee_department_no Number 033 NOT NULL
employee_designation Varchar2 15 NOT NULL
employee_date_of_joining Date - NOT NULL
employee_salary Number 8,2 NOT NULL
employee_email_id Varchar2 30 NOT NULL
employee_contact_no Number 12 NOT NULL
employee_aadhaar_no Number 12 UNIQUE
employee_date_of_resigning Date - -
Output:
Output:
Output:
Output:
v) Display the last day of the month in which employees have resigned.
Query:
SELECT LAST_DAY(Employee_Date_Of_Joining) AS Last_Day_Of_Joining,
LAST_DAY(Employee_Date_Of_Resigning) AS Last_Day_Of_Resigning FROM
uu_employee
WHERE Employee_Date_Of_Resigning IS NOT NULL;
Output:
Output: