lab assignment 1 for dbms
lab assignment 1 for dbms
<employee> Table
1
c. The default value of EmpCity is ‘Jaipur’
(ii) Insert the records of employees.
(iii)Insert the records of employees in a customized manner.
(iv)Display the records of all employees living in city ‘Jaipur’.
(v) Display the designations and IDs of employees having department ‘D1’.
(vi)Display the ID’s and Names of all employees having salary between 20000 and 30000
using BETWEEN…AND OPERATOR.
(vii) Display the IDs, Names, and Salary of all employees living in ‘Jaipur’, or ‘Kota’,
or ‘Ajmer’ using IN operator.
(viii) Display the records of all employees having designation ‘Manager’ or ‘Clerk’
and age is between 30 to 40.
(ix)Display the all unique cities in table.
(x) Display the records of all employees having city value as null.
(xi)Count the total different values of city.
(xii) Update the salary of all employees having designation ‘Manager’ or ‘Clerk’ by
10%.
(xiii) Display the records of all employees in a sorted manner using EmpName as
ascending, and EmpCity as descending.
(xiv) Display the maximum and minimum salary in the table.
(xv) Display the sum and average of the salaries of employees having the designation
as ‘Manager’.
(xvi) Display the IDs, Salaries, and Names of all employees, whose names starts with
‘aj’.
(xvii) Display the IDs, Salaries, and Names of all employees, whose names are 4
characters long and starts with starts with ‘a’, and ends with ‘t’.
(xviii) Display the IDs and Names of all employees, whose names are at least 4
characters long, and 3 and 4 characters are ‘i’ and ‘t’ respectively.
(xix) Display the list of all constraints applied on Employee table.
(xx) Display the structure of table.
2
data types: empID char(3), empName varchar(20), empCity varchar(10), empDOB
date, empSalary numeric(10,2), empDesg varchar(15)
deptID varchar(3), deptName varchar(10), deptBuilding varchar(15)
Sample Entries of the tables:
<employee> Table
<department> Table
(a) Create the above database schema with the following constraints:
i. empName can’t be null.
ii. deptName must be unique.
iii. deptID is the foreign key and references the empID of the employee table.
(b) Insert the records in the tables.
3
itemID varchar(3), itemName varchar(15), itemPrice numeric(10,2)
quantity integer
Sample Entries of the tables:
<suppliers> Table
S2 Britania 10 Kota
-- -- -- --
-- -- -- --
-- -- -- --
-- -- -- --
-- -- -- --
<items> Table
I2 Bread 50.00
I3 Butter 75.25
-- -- --
-- -- --
-- -- --
-- -- --
<shipments> Table
(a) Create the above database schema with the following constraints:
i. suppName can’t be null.
4
ii. itemName can’t be null and must be unique.
iii. suppID and itemID are the two foreign keys in shipments table.
iv. suppID and itemID can’t be null.
v. Quantity can’t be 0 or negative
8. (a) Create a relational database that contains the following tables and insert the following
data into these tables.
<department> Table
deptID deptName
1 Information Technology
2 Electrical
3 Civil
4 Mechanical
5 Chemical
(b) Now, solve the following SQL Queries.
(i) Display the names and contact numbers of all student members.
(ii) Give the names and roll numbers of all students of Information Technology who are
members.
(iii)Display names of Departments whose students are members.
5
(iv)Display names of Departments for which no students are members.
(v) Display names of all Departments.
(vi)Find the number of students of Electrical Department who are members.
(vii) Display information of student members whose name begins with the letter “A”.
(viii) Display all details of Male members only.
(ix)Display data of student members who are currently in semester “3”.
(x) Display data of student female members in alphabetical order.