0% found this document useful (0 votes)
49 views4 pages

SQL Queries Practice Questions

SQL language questions for practice

Uploaded by

julie M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
49 views4 pages

SQL Queries Practice Questions

SQL language questions for practice

Uploaded by

julie M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

SQL Queries Practice Questions

1. Create the following tables with the mapping given below.


a. stu_details (reg_no, stu_name, DOB, address, city)
b. mark_details (reg_no, mark1, mark2, mark3, total)
(i) Alter the table mark_details to add a column average with data type
(ii) Display the months between the DOB and till date.
(iii) Using alter command drop the column address from the table stu_details.

2. Create the following tables with the mapping given below.


a. emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, dept_no,
salary).
b. dept_details (dept_no, dept_name, location).
(i) Display the months between the doj and till date
(ii) Alter the table emp_details to add a primary key constraint on emp_no.

3. Create the following tables with the mapping given below.


a. stu_details (reg_no, stu_name, DOB, address, city)
b. mark_details (reg_no, mark1, mark2, mark3, total)
(i) Display only those rows whose total ranges between 250 and 300.
(ii) Drop the table mark_details.
(iii) Delete the row whose reg_no=161.
(iv) Display all details whose names begins with 'a'.

4. Create the following tables with the mapping given below.


a. book (book_name,author,price,quantity).
b. customer (Cust_id, Cust_name, Addr, ph_no,pan_no)
(i) Truncate the table customer.
(ii) List the author of the book which one have the price of 200.
(iii) List the price of the book which one is between the price of 175 & 250.
(iv) Retrieve all the details from the table book whose author name start with K.

5. Create the following tables with the mapping given below.


a. emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, dept_no, salary).
b. dept_details (dept_no, dept_name, location).
(i) Create a view emp1 from emp_details such that it contains only emp_no and emp_name
(ii) Select dept_no from dept_details and not in emp_details using both the tables.

6. Create the following tables with the mapping given below.


a. Customer (Cust_id, Cust_name, Addr, ph_no,pan_no)
b. Loan (Loan_id, Amount, Interest, Cust_id)
(i) Display the Cust_name having both Loan and Account .
(ii) Display number of Loans, the sum of Loan Amount of a ParticularCustname(“LEENA”)
(iii) Display the Custname doesn’t hold any Account nor taken any Loan
(iv) Add a column nol(number of loans)
7. Create the following tables with the mapping given below.
a. emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, dept_no, salary).
b. dept_details (dept_no, dept_name, location).
(i) Select dept_no from dept_details and not in emp_details using both the tables.
(ii) Create a table named as student and insert values into the table.

8. Create the following tables with the mapping given below.


a. emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, salary).
(i) Add a column dept_no(department number).
(ii) Drop the column salary by altering the table.
(iii) Rename the table as’Employee’.

9. Create the following table with the mapping given below.


a. Customer (Cust_id, Cust_name, Addr,ph_no,pan_no).
(i) Delete the row where cust_name=’NANCY’.
(ii) Update the addr where cust_name=’MATHIK’.
(iii) Display the details of a customer named ‘LITHUANA’.

10. Create the following table with the mapping given below.
a. book(book_name,author_name,price,quantity).
(i) write a query to update the quantity by double in the table book.
(ii) List all the book_namewhose price is greater than Rs.400.
(iii) Retrieve the list of author_name whose first letter is ’a’ along with the book_name and price.

11. Create the following table with the mapping given below.
a. stu_details (reg_no, stu_name, DOB, address, city)
b. mark_details (reg_no, mark1, mark2, mark3, total)
(i) Find the name of the student whose reg_no is’107’.
(ii) Display the details of a particular student whose name is ‘MATHU’.
(iii) Rename the table mark_details as ’academics’.

12. Create the following tables with the mapping given below.
a. assessment(reg_no,name, mark1, mark2, mark3, total)
b. dept_details (dept_no, dept_name, location).
(i) Using alter command drop the column location from the table dept_details.
(ii) Display all dept_name along withdept_no.
(iii) Drop the table dept_details.

13. Create the following tables with the mapping given below.
a. emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, dept_no, salary).
b. dept_details (dept_no, dept_name, location).
(i) Select dept_no from dept_details and not in emp_details using both the tables.
(ii) Display the structure of the table emp_details.
(iii) Display the emp_namegetting highest salary

14. Create the following table with the mapping given below.
a. Product_master(product_name,purchase_prize,sell_prize,profit,quantity,balance)
b. Customer (Cust_id, Cust_name, Addr, ph_no,pan_no)
(i) Display all the customer names along with their address.
(ii) Drop the table customer.
(iii) Change thesell_price to 5000&purchase_price amount to 4000 for any one of the product in
product_master.
15. Create the following table with the mapping given below.
a. stu_details (reg_no, stu_name, DOB, address, city)
b. mark_details (reg_no, mark1, mark2, mark3, total)
(i) Find out the name of all students along with their total marks.
(ii) Change the mark1 as ‘78’ from ‘59’ and alter the total for a particular student.
(iii) Delete all the records and its memory space from the table student.

16. Create the following table with the mapping given below.
a. Administration(employee_salary, development _cost, fund_amount, turn_over,bonus)
b. Emp_details (emp_no, emp_name, DOB, address,doj, mobile_no, dept_no,salry)
(i) Calculate the total and average salary amount of the administration table.
(ii) Display total salary spent for employees.
(iii) Display total fundamount.

17. Create the following table with the mapping given below.
a. emp_details (emp_no, emp_name, DOB, address, doj, mobile_no, dept_no, salary).
(i) List all employees which starts with either B or C.
(ii) Display the names and dob of all employees who were born in Feburary.
(iii) List out the employee names whose salary is greater than 15000.

18. Create the following tables with the mapping given below.
a. Customer (Cust_id, Cust_name, Addr, ph_no,pan_no)
b. Loan (Loan_id, Amount, Interest, Cust_id,branch)
(i) Display the entire loan relation in descending order of the amount.
(ii) Find the names of all branches in loan relation.
(iii) Find all customer id's for loan's with loan amount between 5000 and 15000.

19. Create the following table with the mapping given below.
a. book(book_name,author_name,price,quantity).
(i) Write a query to find out the minimum quantity of books available in the table book.
(ii) Write a query to find the total price of all the books present in the table.
(iii) Write a query to find the average amount of all the books.

20. Consider the following employee and department tables.


a. EMPLOYEE(empno, ename, designation, manager, hiredate, salary, commission,
deptno)
b. DEPARTMENT(deptno, dname, location)
(i) Create the above tables by properly specifying the primary keys and foreign keys and enter at
least five tuples for each relation.
(ii) List the names of employees whose name contain substring ‘LA’.
(iii) List the details of employees of salary are greater than or equal to the average salary of
employee table.

21. Consider the following tables.


a. SAILOR(sid, sname, rating, age)
b. BOATS(bid, bname, colour)
c. RESERVES(sid, bid, day)
(i) Create the above tables by properly specifying the primary keys and foreign keys and enter at
least five tuples for each relation.
(ii) List the sailors in the descending order of their rating.
(iii) List the sailors whose youngest sailor for each rating and who can vote.
(iv) List the sailors who have reserved for both ‘RED’ and ‘GREEN’ boats.
(v) List the details of the oldest sailor for each rating level.
22. Consider the following employee and department tables.
a. EMPLOYEE(empno, ename, designation, manager, hiredate, salary, commission,
deptno)
b. DEPARTMENT(deptno, dname, location)
(i) Create the above tables by properly specifying the primary keys and foreign keys and enter at
least five tuples for each relation.
(ii) List the employees of employee table in descending order of their salaries.
(iii) List the details of highest paid employee in ‘SALES’ department.
23. Consider the following database for a banking enterprise.
a. CUSTOMER_FIXED_DEPOSIT(cust_id,last_name,mid_name,first_name,
fixed_deposit_no, amount, rate_of_interest)
b. CUSTOMER_LOAN(loan_no, cust_id, amount)
c. CUSTOMER_DETAILS(cust_id, acc_type )
(i) Create the above tables by properly specifying the primary keys and foreign keys and enter at
least five tuples for each relation.
(ii) List customer names of all customer who have taken a loan > 3,00,000.
(iii) List customer names of all customer who have the same account type as customer ‘jones
simon’.
(iv) List customer names of all customer who do not have a fixed deposit.

24. Create the following tables with the mapping given below.
a. stu_details (reg_no, stu_name, DOB, address, city)
b. mark_details (reg_no, mark1, mark2, mark3, total)
(i) Display only those rows whose total ranges between 250 and 300.
(ii) Drop the table mark_details.
(iii) Delete the row whose reg_no=161.
(iv) Display all details whose names begins with 'a'.

25. Consider the following database for a banking enterprise.


BRANCH(branch_name, branch_city, assets)
ACCOUNT(accno, branch_name, balance)DEPOSITOR(customer_name, accno)
CUSTOMER(customer_name, customer_street, customer_city)
LOAN(loan_number, branch_name, amount)
BORROWER( customer_name, loan_number)
(i) Create the above tables by properly specifying the primary keys and foreign keys and enter at
least five tuples for each relation.
(ii) Display all the customers who were depositor and borrower.
(iii) Display all the customer name who are only depositor.
(iv) Display all branch name whose assets are greater than assets of branches located in
“Coimbatore” city.

You might also like