SQL Exercises – 15 Days
0% Completed
0 of 15 days completed
SQL Exercises
SOOPRO Pathshala provides day-wise SQL exercises to help students practise database creation, queries, data manipulation, joins, functions, procedures, triggers, indexes, transactions, and other SQL topics.
Practice Instructions:
Read each question carefully and write and execute the required SQL query. Mark a day complete after finishing its exercises. Your progress is saved in this browser.
SQL – Day 1
Day 1 of 15
SOOPRO Pathshala Exercises
Create database name mydb.
Write a query to create table having id,name,gender,city and salary columns, under mydb database.
Rename database mydb to mydatabase.
Write a query to create table employee having id,name,gender,city and salary columns, under mydatabase database.
Write a query to select particular column of table.
Write a query to view all records of table.
Write a query to add new column of table.
Write a query to create table of employee having id,name,gender,city and salary.
Write a query to print details of employee whose first name starts with 'a'.
Write a query to print details of employee whose city starts with 'n'.
Write a query to print details of employee whose first name ends with 'r'.
Write a query to display maximum salary of employee
Write a query to display minimum salary of employee
Write a query to display total salary of employee
Write a query to display average of salary of employee
Write a query to add new column in employee table
Write a query to update multiple fields of employee table
Write a query to drop a column from employee table
Mark Day 1 as Complete
Back to Day List ↑
SQL – Day 2
Day 2 of 15
SOOPRO Pathshala Exercises
Create a student table having id,name,gender,city,mobile and roll number.Insert 5 rows in student table.
Write a query to display unique student name using distinct function.
Write a query to add new column address in student table.
Write a query to change data type of roll number column to bigint.
Write a query to display particular records of student table.
Write a query to drop address column.
Write a query to update multiple fields of student table.
Write a query to truncate student table.
Write a query to drop student table.
Write a query to drop current database.
Mark Day 2 as Complete
Back to Day List ↑
SQL – Day 3
Day 3 of 15
SOOPRO Pathshala Exercises
Write a query to print unique city of all employee
Write a query to print sum of total salary of all employee.
Write a query to print total rows of employee table.
Write a query to count total employees of employee table.
Write a query to print average of employee salary.
Write a query to print record of all employees whose date of birth between 1991 to 2005
Write a query to print record of employees whose city in either noida or kanpur.
Write a query to print record of employees whose city in kanpur,delhi and noida
Write a query to print record of employees whose first name start with 'm'.
Write a query to print top 3 employees.
Write a query to print record of employee and their name in ascending order.
Mark Day 3 as Complete
Back to Day List ↑
SQL – Day 4
Day 4 of 15
SOOPRO Pathshala Exercises
Write a query to print average of salary of employee whose name starts with 'm'
Write a query to print average of salary of employee whose name ends with 'n'
Write a query to print sum of salary of employee whose city in noida,delhi and punjab
Write a query to print sum of salary of employee whose city not in faridabad,punjab and delhi
Write a query to apply primary key on table column
Write a query to apply unique key on table column
Write a query to do not allow null value on specific column
Write a query to allow number in column if it is positive number
Write a SQL statement that display all the information about all salesperson having salesman_id,name,city and commission.
Write a SQL query to display sum of max and min of employee salary
Write a SQL query to display average of max and min of employee salary
Write a sql query to display cities of employees whose salary is greater than 20000
Write a sql query to display gender of employee whose salary is less than 50000
Mark Day 4 as Complete
Back to Day List ↑
SQL – Day 5
Day 5 of 15
SOOPRO Pathshala Exercises
Create two tables department and employee, in department table add four records having id-1,2,4 & 5 and in employee table add six records having id-1,2,3,4,5 and 6.
Perform inner join on department and employee tables.
Perform left join on department and employee tables.
Perform right join on department and employee tables.
Perform full outer join on department and employee tables.
Write a sql statement that displays all the information about all salesperson.
Write a sql query to display the sum of two number 10 and 15 from RDBMS server.
Write a sql query to display the result of an arithmetic operation.
Write a sql statement to display the specific column such as name and commission for all the salesperson.
Write a sql query to display the column in a specific order, such as order date, and purchase amount for all the orders.
Mark Day 5 as Complete
Back to Day List ↑
SQL – Day 6
Day 6 of 15
SOOPRO Pathshala Exercises
Write a query to print even and odd using scalar function in sql.
Write a query to print positive or negative number using scalar function in sql.
Write a query to print square of any number using scalar function in sql.
Write a query to print cube of any number using scalar function in sql.
Write a query to print sum of three integer using scalar function in sql.
Write a query to print sum of three integer using scalar function in sql.
Write a query to print your name using scalar function in sql.
Write a query to print total employees gender wise. HINT: use stored procedure having (input and output parameter).
Write a query to print total student city wise. HINT: use stored procedure having(input and output parameter)
Write a query to perform inner join inside stored procedure and print it.
Mark Day 6 as Complete
Back to Day List ↑
SQL – Day 7
Day 7 of 15
SOOPRO Pathshala Exercises
Write a query to return total sum of employee salary using scalar function.
Write a query to return average salary of employee using scalar function.
Write a query to return records of employee whose name start with 'a' using inline table valued function.
Write a query to return records of employee whose salary greater than 10000 using inline table valued function.
Write a query to perform union and union all in sql.
Write a query to perform intersect and except in sql.
Write a query to print total salary of employee city wise.
Write a query to print average salary of employee gender wise.
Write a query to print average salary of employee city wise.
Mark Day 7 as Complete
Back to Day List ↑
SQL – Day 8
Day 8 of 15
SOOPRO Pathshala Exercises
Find 6th hignest salary of employee.
Find 3rd highest salary of employee.
Create procedure that print any highest salary.
Create procedure that print sum of second highest salary and fourth highest salary.
Create procedure to return difference of sum of salary and max of salary using output parameter.
Print inner join using stored procedure on window form.
Print difference of second highest and fourth highest salary of employee using stored procedure.
Create trigger on employee table that gets fired and print some message on insertion of any record in employee table
Create trigger on student table that gets fired and print message on deletion of any record from employee table.
Create trigger on employee table that print deleted record from employee table.
Mark Day 8 as Complete
Back to Day List ↑
SQL – Day 9
Day 9 of 15
SOOPRO Pathshala Exercises
Create clustered index on customer(id) table.
Create non clustered index on person(id) and person(name) table
Create unique index on employee(id) table.
Write a query to drop index
Write a query to view all indexes of current table.
Use rollback transaction to delete record of student.
Use commit transaction to delete record of student.
Try to see uncommited transaction in other connection.
Use try and catch block for divide by zero exception in sql.
Execute transaction for update query under stored procedure.
Mark Day 9 as Complete
Back to Day List ↑
SQL – Day 10
Day 10 of 15
SOOPRO Pathshala Exercises
Write a query to return table using table valued function..
Waq to return average of employee salary using inline table valued function.
Waq to return product of employee salary using inline table valued function.
Write short notes on function in sql.
Write short notes on trigger in sql.
Do practice on aggregate function.
Create a function that takes a number as an argument, increments the number by +1 and returns the result.
Create a function that takes age in years and returns the age in days.
Create a function that takes voltage and current and returns the calculated power.
Create a local temporary table name person having id,name,gender, city and salary.
Mark Day 10 as Complete
Back to Day List ↑
SQL – Day 11
Day 11 of 15
SOOPRO Pathshala Exercises
Create a local temporary table name student having id,name,gender, city and salary.
Create a global temporary table name customer having id,name,amout, city
Create a local temporary table name student having id,name,gender, city and salary.
Create a trigger inside procedure for insert operation on sql table . When trigger gets fired message should be displayed.
Create a trigger inside procedure for delete opertaion on sql table. when trigger gets fired message should be displayed.
Create cursor to fetch first record of student table without variable.
Create cursor to fetch last record of student table without variable.
Create cursor to fetch second last record od student table without variable.
Create cursor to fetch id and name of first record using variable.
Return total salary of employees of a table inside procedure.
Return total salary of employees citywise inside procedure.
Mark Day 11 as Complete
Back to Day List ↑
SQL – Day 12
Day 12 of 15
SOOPRO Pathshala Exercises
Waq to add new column in sql table
Waq to change data type of column in sql table
Waq to change size of data type of column in sql table.
Waq to drop column of sql table.
Waq to rename column name of sql table.
Mark Day 12 as Complete
Back to Day List ↑
SQL – Day 13
Day 13 of 15
SOOPRO Pathshala Exercises
Waq to add column in specified position (hint- do r&d)
Waq to drop last column of employee table.
Waq to drop first column of employee table.
Waq to copy only top 3 records from person table to person1 table.
Waq to copy only top 5 records from person table to person1 table.
Mark Day 13 as Complete
Back to Day List ↑
SQL – Day 14
Day 14 of 15
SOOPRO Pathshala Exercises
Waq to count toal rows of employee table
Waq to count only distinct rows of employee table
Waq to find duplicate value in column of sql table.
Mark Day 14 as Complete
Back to Day List ↑
SQL – Day 15
Day 15 of 15
SOOPRO Pathshala Exercises
Waq to create view for top 3 records of employee table
Waq to create view for last 3 records of employee table.
Waq to print 2nd highest and 4th highest salary of employee.
Mark Day 15 as Complete
Back to Day List ↑