You are on page 1of 25

SQL File Assignments

 Last Date for submission: 30th April 2022


 File should be spiral binded
 Front page, Index page and list of questions are given on the next page
BANARSIDAS CHANDIWALA INSTITUTE OF
PROFESSIONAL STUDIES

INFORMATION Systems MaNAGEMENT

Practical File

Submitted in partial fulfillment of the requirements


for the award of the degree of
Bachelor of Business Administration (BBA)
To
Guru Gobind Singh Indraprastha University, Delhi

Submitted by: Rohit Sharma

Student Name: Rohit Sharma

Enrolment No.: 03850501720

Shift: 2nd Shift

Batch: 2020-23

BanarsidasChandiwala Institute of Professional Studies, New Delhi


2021-22
INDEX

S.N Practical Signature


o
Structured Query Language
1. Write SQL queries to create table and insert data.
2. Write SQL queries to select data
3. Write SQL queries for aggregate functions
4. Write SQL queries for Select and update
5. Write SQL queries for applying constraints
6. Write SQL queries using Alter command
Assignment 1
a. Write an SQL command that will create a table named Test1 with the following fields
and types: ENoint, FirstName VARCHAR(24), PAddress VARCHAR(30), Age int ,
Giftvalue NUMERIC(10,2).
Ans a create table firsttable(sno int,firstname varchar(24),paddress
varchar(30),age int,gift numeric(10,2))

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

ENo FirstName PAddress Age Giftvalue


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
B insert into FirstTable (sn, firstname, paddress, age, gift) values
(01,'ram', 'dwarka sector 10', 41, 200)
insert into FirstTable (sn, firstname, paddress, age, gift) values (02,
'sita', 'janakpuri block c', 26, 250)
insert into FirstTable (sn, firstname, paddress, age, gift) values (03,
'rajesh','dwarka sector 15', 23, 200)
insert into FirstTable (sn, firstname, paddress, age, gift) values (04,
'ajit', 'noida sector 11', 35, 150)
insert into FirstTable (sn, firstname, paddress, age, gift) values (05,
'rita', 'noida sector 11', 40, 150)

Assignment 2: Select Queries for table Test1


a. Write an SQL query to display all the records
select*from FirstTable
B) Write an SQL query to display all the records where age >40
select*from firsttable where age>40
C) Write an SQL query to display Fname, Age from the table
select Firstname,Age from firsttable

D Write an SQL query to display Fname, Age, Gift where Age > 35 from the table
select Firstname,Age,Gift from firsttable where age>35
E) Write an SQL query to display all record where Gift > 200 and Age >20
select*from firsttable where gift>200 and age>20

F) Write an SQL query to display all record where Gift > 200 or Age >20
select*from FirstTable where Gift>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)as "TOTAL OF AGE COL" from firsttable

B) Write a query to average of the cost of gifts.


select AVG(GIFT)as "AVG OF GIFT VALUE COL" FROM firsttable

C)Write a query to display the name and age of the youngest member
select FIRSTNAME from firsttable where age=(select MIN(AGE)from firsttable)

D)Write a query to count the number of candidates whose age in more than 30.
select COUNT(Firstname)from firsttable where age>30

E)Write a query to find the name and cost of the costliest gift.
select FirstName from firsttable where gift=(select MAX(gift)from firsttable)
Assignment 4: Applying functions and modification queries

a. Create a table with the following specifications

Field name Data type


EMPID INT
DEPT CHAR(5)
EMPNAME VARCHAR(15)
ADDRESS VARCHAR(30)
SALARY NUMERIC(7)
A)create table SecondTable (EMPID int Primary key, DEPT CHAR (5), EMPNAME
VARCHAR(15), ADDRESS VARCHAR(30), SALARY NUMERIC(7))
select * from SecondTable

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 Cross 14000
108 RD03 Philip Park Avenue 15000
109 RD03 Henry Malibu Beach 14000
110 AD01 Frank St. Peters Lane 7000
B insert into SecondTable values (101, 'RD01','Price','Park Way',15000)
insert into SecondTable values (102, 'RD01','Harry','Pebble Street',12000)
insert into SecondTable values (103,'RD02','Tom','Rose Garden',11000)
insert into SecondTable values (104,'RD02','Susan','Model Town',10000)

insert into SecondTable values (105,'ED01','Mark','Victor Crescent',10000)


insert into SecondTable values (106,'AD01','francis','Chelmsford Park',13000)
insert into SecondTable values (107,'GR01','Robert','Downtown Cross',14000)
insert into SecondTable values (108,'RD03','Philip','Park Avenue',15000)
insert into SecondTable values (109,'RD03','Henry','Malibu Beach',14000)
insert into SecondTable values (110,'AD01','Frank','St.Peters Lane',7000)
select*from SecondTable
C) Find names for all employees who work for the RD01 department.
SELECT empname from SecondTable where DEPT = 'RD01';

D) How many employees work in department starting from RD.


select COUNT(empname) from SecondTable where DEPT like 'RD%'

E) What is the maximum and minimum of the salaries.


SELECT MIN(salary) as minimum, MAX(salary) as maximum from SecondTable
F) Name the employees and their department whose salaries are greater than 12000.
select EMPNAME,DEPT from SecondTable where salary>12000;

G) Find the number of employees in each department.


select DEPT,COUNT(EMPNAME) from SecondTable group by DEPT

H) List the employees in increasing order of their salaries.


SELECT EMPNAME, SALARY from SecondTable order by salary asc

I) Modify the table so that Susan is assigned to AD01 department.


update SecondTable set DEPT = 'AD01' WHERE empname = 'susan';

J) Name the employee in department RD03 who lives in Park Avenue.


select EMPNAME,DEPT,ADDRESS from SecondTable where DEPT = 'RD03'AND address
= 'parkavenue'

K) Find the Average salary.


select AVG(salary) from SecondTable

L) Count the number of employees.


select COUNT(empname) from SecondTable
Assignment 5: Constraints

a. Create a table EMP_TABLEwith the following specifications

Field name Data type


EMPID CHAR(4), Primary Key
DEPT CHAR(5), NOT NULL
EMPNAME VARCHAR(15)
SALARY NUMERIC(7)

A) create table EMP_TABLE (EMPID CHAR(4),DEPT CHAR(5),EMPNAME


VARCHAR(15),SALARY NUMERIC(7))

B) Make the following entries in the table

EMPID DEPT EMPNAME SALARY


M101 RD01 Prince 150000
M102 RD01 Harry 120000
F103 FD01 Tom 110000
M104 RD01 Susan 100000
P105 ED01 Mark 100000
M106 RD01 Francis 130000
P107 ED01 Robert 140000
P108 ED01 Philip 150000
F109 FD01 Henry 140000
H110 AD01 Frank 70000
Ans b) Insert into EMP_TABLE (M101,RD01,Prince,150000)

Insert into EMP_TABLE (M102,RD01,Harry, 120000)

Insert into EMP_TABLE (F103,FD01,Tom,110000)

Insert into EMP_TABLE (M104,RD01,Susan,100000)

Insert into EMP_TABLE (P105,ED01,Mark,100000)

Insert into EMP_TABLE (M106,RD01,Francis,130000)

Insert into EMP_TABLE (P107,ED01,Robert,140000)

Insert into EMP_TABLE (P108,ED01,Philip,150000)

Insert into EMP_TABLE (F109,FD01,Henry,140000)

Insert into EMP_TABLE (H110,AD01,Frank,70000)

C Write an SQL query to display the table in ascending order of their names
select * from EMP_Table order by EMPNAME
D)Write a SQL query that returns the average salary using the alias “Average salary”
Select AVG(SALARY) as “Average Salary” from EMP_TABLE

E)Write a SQL query to display the records of employees whose names start with letter ‘P’ or ‘H’

SELECT EMPNAME FROM [EMP_TABLE] where EMPNAME LIKE 'P%' or EMPNAME


LIKE 'H%'
Assignment6: Alter command
Create a table Student1 with the following structure:
Roll no number 3
Name varchar 20
Marks number 6

Ans create table Student2 (RollNoNumeric(3),Name Varchar(20),Marks Numeric(4))


Write the following SQL queries

1. Add new columns pincode and city to Student1

Alter Table Student2 add pincode numeric, city varchar

2. Change the width of pincode to 6

Alter Table Student2 Alter column Pincode numeric (6)


3. Add a primary key

Alter Table Student2 ADD Constraints Rollno Primary key(Rollno)

4. Add a not null constraint

Alter Table Student2 Alter column Rollnonumeric(3) NOT NULL

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

Alter Table Student2 ADD Constraint Marks check(Marks >=0 and Marks<=100)

You might also like