You are on page 1of 36

BANARSIDAS CHANDIWALA INSTITUTE OF

PROFESSIONAL STUDIES

INFORMATION SYSTEM MANAGEMENT LAB 


BBA-212
BBA 2019-22

Submitted to:                    Submitted by:


Ms. Pooja Yadav       Ishandeep Singh
Assistant Professor                                      03061201719
BBA 4th Sem 1st Shift

Affiliated to Guru Gobind Singh Indraprastha University, New Delhi


S. No Assignment

1 Assignment 1
      -    To write SQL queries to create table and insert data

2 Assignment 2
 To write SQL queries using select command

3 Assignment 3
 To write SQL queries using aggregate functions 

4 Assignment 4
 To create a table with constraints

5 Assignment 5
 To write SQL queries for select and update command

6 Assignment 6
 To write SQL queries with alter command

7 Assignment 7
 To write SQL queries on Create table command
 Insert command
 Select command
 Modify command
 Delete command
 Using different mathematical functions 

8 Assignment 8
 To write SQL queries on Create table command
 Insert command
 Select command
 Modify command
 Delete command
 Using different mathematical functions

INDEX
SQL
Assignment 1
a. Write an SQL command that will create a table named Test1 with the following fields
and types: idno NUMERIC (10), fname VARCHAR (24), address VARCHAR (30),
age NUMERIC (10), giftvalue NUMERIC (10,2).

Create Table Test1


(Idno NUMERIC (10),
fname VARCHAR (24),
address VARCHAR (30),
age NUMERIC (10),
giftvalue NUMERIC (10,2));

b. Insert the following items in the table you have created


Eno FirstName Address1 Age Gift
01 Ram Dwarka sector 41 200
10

02 Sita Janakpuri 26 250


block C

03 Rajesh Dwarka sector 23 200


15

04 Ajit Noida sector 35 150


11

05 Rita Noida sector 40 200


11
i) Insert into Test1
(Idno, fname, address, age, giftvalue)
Values
("01", "Ram", "Dwarka Sector 10", "41", "200");

ii) Insert into Test1


(Idno, fname, address, age, giftvalue)
Values
("02", "Sita", "Janakpuri Block C", "26", "250");

iii) Insert into Test1


(Idno, fname, address, age, giftvalue)
Values
("03", "Rajesh", "Dwarka Sector 15", "23", "200");

iv) Insert into Test1


(Idno, fname, address, age, giftvalue)
Values
("04", "Ajit", "Noida Sector 11", "35", "150");
v) Insert into Test1
(Idno, fname, address, age, giftvalue)
Values
("05", "Rita", "Noida Sector 11", "40", "200");

Assignment 2: Select Queries for table Test1


a. Write an SQL query to display all the records

Select * from Test1;

b. Write an SQL query to display all the records where age >40

Select * from Test1 where age>40;


c. Write an SQL query to display Fname, Age from the table

Select fname, age from Test1;

d. Write an SQL query to display Fname, Age, Gift where Age > 35 from the table

Select fname, age, giftvalue from Test1 where age>35;


e. Write an SQL query to display all record where Gift > 200 and Age >20

Select * from Test1 where giftvalue>200 And age>20;

f. Write an SQL query to display all record where Gift > 200 or Age >20

Select * from Test1 where giftvalue>200 or age>20;


Assignment 3: Queries for aggregate functions for table Test1
a. Write SQL query to add the age of all records.

Select Sum(age) from Test1;

b. Write a query to average of the cost of gifts.

Select avg(giftvalue) from Test1;


c. Write a query to display the name and age of the youngest member

Select fname, min(age) from Test1;

d. Write a query to count the number of candidates whose age in more than 30.

Select Count(fname) from Test1 where age>30;


e. Write a query to find the name and cost of the costliest gift.

Select fname, max(giftvalue) from Test1;

Assignment 4: Constraints
a. Create a table “Employee” with the following specifications
Field name Data type
EMPID INT, Primary Key
DEPT VARCHAR (5)
EMPNAME CHAR (15), Not Null
ADDRESS VARCHAR (30)
SALARY NUMERIC (7), Salary>=7000

Create table Employee


(EMPID INT Primary Key,
DEPT VARCHAR (5),
EMPNAME CHAR (15) NOT NULL,
ADDRESS VARCHAR (30),
SALARY NUMERIC (7), CHECK (SALARY>=7000));
b. Make the following entries in the table
EMPID DEPT EMPNAME ADDRESS SALARY
101 RD01 Prince Park Way 15000
102 RD01 Harry Pebble Street 12000
103 RD02 Tom Rose Garden 11000
104 RD02 Susan Model Town 10000
105 ED01 Mark Victor Crescent 10000
106 AD01 Francis Chelmsford Park 13000

107 GR01 Robert Downtown 14000


Cross
108 RD03 Philip Park Avenue 15000
109 RD03 Henry Malibu Beach 14000
110 AD01 Frank St. Peters Lane 7000

i) Insert into Employee


(EMPID, DEPT, EMPNAME, ADDRESS, SALARY)
Values
("101", "RD01", "Prince", "Park Way", "15000");
ii) Insert into Employee
(EMPID, DEPT, EMPNAME, ADDRESS, SALARY)
Values
("102", "RD01", "Harry", "Pebble Street", "12000");

iii) Insert into Employee


(EMPID, DEPT, EMPNAME, ADDRESS, SALARY)
Values
("103", "RD02", "Tom", "Rose Garden", "11000");

iv) Insert into Employee


(EMPID, DEPT, EMPNAME, ADDRESS, SALARY)
Values
("104", "RD02", "Susan", "Model Town", "10000");

v) Insert into Employee


(EMPID, DEPT, EMPNAME, ADDRESS, SALARY)
Values
("105", "ED01", "Mark", "Victor Crescent", "10000");

vi) Insert into Employee


(EMPID, DEPT, EMPNAME, ADDRESS, SALARY)
Values
("106", "AD01", "Francis", "Chelmsford Park", "13000");

vii) Insert into Employee


(EMPID, DEPT, EMPNAME, ADDRESS, SALARY)
Values
("107", "GR01", "Robert", "Downtown Cross", "14000");
viii) Insert into Employee
(EMPID, DEPT, EMPNAME, ADDRESS, SALARY)
Values
("108", "RD03", "Philip", "Park Avenue", "15000");

ix) Insert into Employee


(EMPID, DEPT, EMPNAME, ADDRESS, SALARY)
Values
("109", "RD03", "Henry", "Malibu Beach", "14000");

x) Insert into Employee


(EMPID, DEPT, EMPNAME, ADDRESS, SALARY)
Values
("110", "AD01", "Frank", "St. Peters Lane", "7000");

Assignment 5: Select & Update 


a. Find names for all employees who work for the RD01 department.

Select * from Employee


Where dept = "RD01";
b. How many employees work in department starting from RD.?

Select count (EMPNAME) from Employee


Where dept like "Rd%";

c. What is the maximum and minimum of the salaries?

Select Max (Salary) from Employee;


Select Min (Salary) from Employee;

d. Name the employees and their department whose salaries are greater than 12000.

Select EMPNAME, DEPT from Employee


Where Salary>12000;
e. Find the number of employees in each department.

Select count (EMPNAME), DEPT from Employee


Group By DEPT;

f. List of employees in increasing order of their salaries.

Select Salary from Employee


Order by Salary asc;
g. Modify the table so that Susan is assigned to AD01 department.

Update Employee
Set DEPT =“AD01”
Where EMPNAME “Susan”;

h. Change the salary of all the employees to AD01 to salary*1.2.

Update Employee
Set Salary=Salary*1.2
Where DEPT = “AD01”;
i. Name the employee in department RD03 who lives in Park Avenue.

Select EMPNAME from Employee


Where DEPT="RD03" and ADDRESS="Park Avenue";

j. Find the Average Salary.

Select Avg(Salary) from Employee;


k. Count the number of employees.

Select count(EMPID) from Employee;

Assignment 6: Alter
Create a table Student1 with the following structure:
Roll no number 3
Name varchar 20
Marks number 6

Create table Student1


( Roll no numeric (3), Name varchar (20), Marks numeric (6));

1. Add new columns pin code and city to Student1

Alter table Student1


Add city char (20);
Alter table student1
Add pin code numeric (7);
2. Change the width of pin code to 6.

Alter table Student1


Alter column pin code numeric (6);

3. Add a new column with Primary Key Constraint.

Alter table Student1


Add Assignment varchar (20) Primary Key;

4. Add a new column with Not Null Constraint.

Alter table Student1


Add Name char (20) Not Null;

5. Add construct check to the Marks Column (Marks>=0 and Marks<=100)

Alter table Student1


Add check (marks>=0 and <=100);

Assignment 7
Write SQL queries for the following:
a. To create a table Client Details with the following specifications.

Column Name Data Type Size Attributes

Client No Char 6 Primary Key

Name Varchar 30 Not Null

City Varchar 20

State Varchar 20

Pin Code Numeric 6

Bal_due Numeric 10,2


Create table Client Details
(Client No char (6) primary key, Name varchar (30) Not Null, City varchar (20),
State varchar (20), Pin Code numeric (6), Bal due numeric (10,2));

b. To insert the following data into the table

Client No Name City State Pin Code Bal_due

C00001 Ramesh Kumar Mumbai Maharashtra 400054 15000

C00002 Vandana Saitwal Madras Tamil Nadu 780001 0

C00003 Pramada Jaiswal Mumbai Maharashtra 400057 5000

C00004 Rukmini Delhi Delhi 100001 2000

Insert into Client Details (Client No, Name, City, State, Pin Code, Bal_due)
Values
(“C00001", "Ramesh Kumar", "Mumbai", "Maharashtra", "400054", "15000”);
Insert into Client Details (Client No, Name, City, State, Pin Code, Bal_due)
Values
(“C00002", "Vandana Saitwal", "Madras", "Tamil Nadu", "780001", "0”);

Insert into Client Details (Client No, Name, City, State, Pin Code, Bal_due)
Values
(“C00003", "Pramada Jaiswal", "Mumbai", "Maharashtra", "400057", "5000”);

Insert into Client Details (Client No, Name, City, State, Pin Code, Bal_due)
Values
(“C00004", "Rukmini", "Delhi", "Delhi", "100001", "2000”);
c. To display the names of all the clients.

Select Name from Client Details;

d. To display the maximum balance due under the heading “Max Bal_due”.

Select Max (Bal Due) from Client Details;


e. To change the pin code of client no C00001 to 400058.
Update Client Details
Set Pin Code="400058"
Where Client No="C00001";

f. To display the details of clients in increasing order of their balance due.

Select Bal Due from Client Details


Order By Bal Due;
g. To display the Name and Bal_due of clients who live in Mumbai and them
Bal_due<10000.
Select Name, Bal Due from Client Details
Where City="Mumbai" and Bal Due<10000;

Assignment 8
1.  Write an SQL command that will create a table named Friend with the following fields
and types:  idno NUMERIC (10) PRIMARY KEY, fname VARCHAR (24), address
VARCHAR (30), age INT NOT NULL, giftvalue NUMERIC (10,2).
Create table Friend
(Idno numeric (10) Primary Key, fname varchar (24), address varchar (30),
age int Not Null, giftvalue numeric (10,2));
2.  Insert the following items in the table you have created
Idno FName Address Age Giftvalue 

01 Ram Dwarka sector 10 41 200

02 Sita Janakpuri block c 26 250

03 Rajesh Dwarka sector 15 23 200

04 Ajit Noida sector 11 35 150

05 Rita Noida sector 11 40 200

Insert into Friend (Idno, Fname, Address, Age, Giftvalue)


Values
(“01", "Ram", "Dwarka Sector 10", "41", "200");

Insert into Friend (Idno, Fname, Address, Age, Giftvalue)


Values
(“02", "Sita", "Janakpuri Block C", "26", "250");

Insert into Friend (Idno, Fname, Address, Age, Giftvalue)


Values
(“03", "Rajesh", "Dwarka Sector 15", "23", "200");

Insert into Friend (Idno, Fname, Address, Age, Giftvalue)


Values
(“04", "Ajit", "Noida Sector 11", "35", "150");

Insert into Friend (Idno, Fname, Address, Age, Giftvalue)


Values
(“05", "Rita", "Noida Sector 11", "40", "200");
3.  Write an SQL command to add a new record in the Friend table with details of your
choice.
Insert into Friend (Idno, Fname, Address, Age, Giftvalue)
Values
("06", "Akaash", "Rajouri Garden 87", "19", "300”);
4.  Write an SQL query to display all the records whose name starts with R.
Select * from Friend where fname like "R%";

5.  Write an SQL query that will insert a complete record into the Friend table with these
values for the respective fields:  '123', 'Tasmanian Devil', 'Tasmania', 23, 29.99.
Insert into Friend (Idno, fname, address, age, giftvalue)
Values
(“123”, “Tasmanian Devil”, “Tasmania”, “23”, “29.99”);
6.  Write an SQL query to insert a record with idno as 21, name as Urvashi, address as Delhi.
Insert into Friend (Idno, Fname, Address, Age, Giftvalue)
Values
(“21", "Urvashi", "Delhi", "30", "450”);

7. Write an SQL query to change the age of Sita to 28.


Update Friend
Set Age="28"
Where fname="Sita";
8.  Write an SQL query to delete the record of idno 123.
Delete from Friend Where Idno="123";

9.  Write an SQL query that will update the giftvalue to 49.99 for all people in the Friend
table who are 31 and older.
Update Friend
Set Giftvalue="49.99"
Where age>="31";
10.  Write an SQL query that will add a new field/column ‘City’ to the Friend table.  You can
choose its type and size.
Alter table Friend
Add City char (17);
11.  Write an SQL query to delete the field ‘City’ that you added in the Friend table.
Alter table Friend
Drop Column City;

12. Write an SQL query to insert a record with name Ram and other details of your choice.
Insert into Friend (Idno, Fname, Address, Age, Giftvalue)
Values
(“23", "Ram", "Greater Kailash 75", "57", "567”);

13.  Write an SQL query to display fname and age of all the records. 
Select Fname, age from Friend;
14. Write SQL query to add the age of all records.
Select sum (age) from Friend;
15. Write a query to average of the cost of gifts.
Select avg (giftvalue) from Friend;

16. Write a query to display the name and age of the youngest member
Select Fname, min(age) from Friend;
17. Write a query to count the number of candidates whose age is more than 30 years.
Select count (Fname) from Friend where age> "30”;

18. Write a query to find the name and cost of the costliest gift.
Select Fname, max (giftvalue) from Friend;
19.  Write an SQL query that will delete all records from the Friend table where the giftvalue
is over 100.
Delete from Friend
Where Giftvalue>100;

20. Write a query to delete all the records. 


Delete from Friend;

You might also like