Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
1 views

lab assignment 1 for dbms

The document outlines a DBMS Lab assignment for B.Tech. (CS) III Semester students, detailing various SQL commands and queries related to database management. It includes tasks such as creating tables, inserting records, applying constraints, and executing complex queries on employee, department, supplier, item, shipment, student, and sales tables. The assignment emphasizes practical application of SQL syntax and database concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

lab assignment 1 for dbms

The document outlines a DBMS Lab assignment for B.Tech. (CS) III Semester students, detailing various SQL commands and queries related to database management. It includes tasks such as creating tables, inserting records, applying constraints, and executing complex queries on employee, department, supplier, item, shipment, student, and sales tables. The assignment emphasizes practical application of SQL syntax and database concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

B.Tech.

(CS) III Semester


(SECTION A & B)
DBMS Lab. (CS 212L) Assignment - I
1. Write the general syntax and also give the examples for the following:
a. CREATE command
b. INSERT command
c. UPDATE command
d. SELECT command
2. Write the syntax for the ALTER TABLE command to add and remove the columns to the
table.
3. Write the syntax for applying the constraints at the time of creation of a table at the table
level as well as column level. The constraints should be specified by giving suitable
names.
4. Write the syntax for adding and removing the constraints after creation of table.
5. Consider the following Employee table:

{empID, empName, empCity, empAge, empSalary, empDesg, empDept}

data types: empID varchar(3), empName varchar(20), empCity varchar(10),


empSalary numeric(10,2), empDesg varchar(15), EmpDept varchar(3)

<employee> Table

empID empName empCity empAge empSalary empDesg empDept


E1 Ram Jaipur 47 15000 Manager D1
E2 Shyam Kota 42 18000 DBA D2
E3 Geeta Ajmer 22 16000 Programmer D1
-- -- -- -- -- -- --
-- -- -- -- -- -- --
-- -- -- -- -- -- --

Write the following queries for the above table:

(i) Create the above table with the following constraints:


a. EmpName can’t be null.
b. EmpSalary must not be less than 8000.

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.

6. Consider the following database schema:


employee {empID, empName, empCity, empDOB, empSalary, empDesg, empDeptID}
department {deptID, deptName, deptBuilding}

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

empID empName empCity empDOB empSalary empDesg empDeptID


E1 Ram Jaipur 10-Mar- 15000 Manager D1
1985
E2 Shyam Kota 12-Apr- 18000 DBA D2
1990
E3 Geeta Ajmer 10-Dec- 16000 Programmer D1
2001
-- -- -- -- -- -- --
-- -- -- -- -- -- --
-- -- -- -- -- -- --

<department> Table

deptID deptName deptBuilding


D1 Accounts Vidhya Mandir
D2 HR Vidhya Mandir
D3 Education Surya Mandir
-- -- --
-- -- --
-- -- --

(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.

7. Consider the following database schema:


suppliers {suppID, suppName, suppStatus, suppCity}
items {itemID, itemName, itemPrice}
shipments {suppID, itemID, quantity}
data types: suppID char(3), suppName varchar(30), suppStatus integer, suppCity
varchar(15)

3
itemID varchar(3), itemName varchar(15), itemPrice numeric(10,2)
quantity integer
Sample Entries of the tables:
<suppliers> Table

suppID suppName suppStatus suppCity


S1 Amul 20 Jaipur

S2 Britania 10 Kota

S3 Mother Dairy 15 Ajmer

-- -- -- --
-- -- -- --
-- -- -- --
-- -- -- --
-- -- -- --

<items> Table

itemID itemName itemPrice


I1 Cookies 35.50

I2 Bread 50.00

I3 Butter 75.25

-- -- --
-- -- --
-- -- --
-- -- --

<shipments> Table

suppID itemID quantity


S1 I1 50
S2 I2 70
S3 I3 30
-- -- --
-- -- --
-- -- --

(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.

stud_member {rollNo, firstName, middleName, surName}


department {deptID, deptName }
data types: rollNo integer, firstName varchar(15), middleName varchar(15), surName
varchar(15) , deptID integer, semester integer, contactNo varchar(10), gender char(1)
deptID integer, deptName varchar(15)
<stud_member> Table

rollNo firstName middleName surName depID semester contactNo gender

1 Ankur Samir Kahar 1 1 272121 M


2 Dhaval Dhiren Joshi 1 1 232122 M
3 Ankita Biren Shah 1 1 112121 F
10 Komal Maheshkumar Pandya 2 3 123123 F
13 Amit Jitenkumar Mehta 3 3 453667 M
23 Jinal Ashish Gandhi 2 1 323232 M
22 Ganesh Asha Patel 2 3 124244 M
4 Shweta Mihir Patel 3 1 646342 F
7 Pooja Mayank Desai 3 3 328656 F
8 Komal Krishnaraj Bhatia 2 3 257422 F
43 Kiran Viraj Shah 1 1 754124 F

<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.

9. Create the following sales table


sales {orderID, orderDate, orderPrice, orderQty, customerName}
data types: orderID integer, orderDate date, orderPrice numeric(10,5), orderQty
integer, customerName varchar(20)
<sales> Table
orderID orderDate orderPrice orderQty customerName
1 12/22/2005 160 2 Smith
2 08/10/2005 190 2 Johnson
3 07/13/2005 500 5 Baldwin
4 07/15/2005 420 2 Smith
5 12/22/2005 1000 4 Wood
6 10/2/2005 820 4 Smith
7 11/03/2005 2000 2 Baldwin

Solve following queries using Aggregate Function for above table:


(i) Count how many orders have made a customer with customerName of Smith.
(ii) Find number of unique customers that have ordered from the store.
(iii)Find out total no. of items ordered by all the customers.
(iv)Find out average number of items per order.
(v) Find out the average orderQty for all orders with orderPrice greater than 200
(vi)Find out what was the minimum price paid for any of the orders.
(vii) Find out the highest orderPrice from the given sales table
(viii) List out unique customers‟ name only from the table.
(ix)List out name of the customers who have given order in the month of DECEMBER
(x) Find out the total amount of money spent for each of the customers.
(xi)Select all unique customers, who have spent more than 1200 in the store.
(xii) Select all customers that have ordered more than 5 items in total from all their orders.
(xiii) Select all customers who have spent more than 1000, after 10/01/2005.
(xiv) Select orders in increasing order of order price.
(xv) Select orders in decreasing order of order price.

You might also like