SQL Programming Language

This test consists of questions related to SQL queries and programming, which is useful for CS and Gate students.

17 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Consider the following table:

Product Table:

|Category|Product_Name|Product_Price|State|Country| |---|---|---|---|---| |Furniture|Chair|700 Rs|Colordo|US| |Furniture|Bed|2000 Rs|Colordo|US| |Electronics|TV|1200 Rs|Capetown|Africa| |Electronics|Radio|700 Rs|Delhi|India| |Leather|Bag|800 Rs|Mumbai|India| |Garments|Jacket|2300 Rs|Nairobi|Kenya|

Determine the name and price of the product of the US country. Select the correct option.

  1. SELECT product_name FROM product WHERE country= 'US'
  2. SELECT product_name FROM product WHERE product_name IN (SELECT product_name FROM Product WHERE country= US)
  3. SELECT product_name FROM product WHERE product_name IN (SELECT product_name FROM Product WHERE country= 'US')
  4. Both (1) and (3)
  5. None of the above
Question 2 Multiple Choice (Single Answer)

Which of the following SQL query is the example of equi join?

  1. SELECT first_name, last_name, subject FROM student_details WHERE subject = 'Economics'
  2. SELECT first_name, last_name, subject FROM student_details WHERE marks>90
  3. SELECT first_name, last_name, subject FROM student_details WHERE marks=>90
  4. Both (1) and (3)
  5. None of the above
Question 3 Multiple Choice (Single Answer)

Consider the following table:

Product Table:

|Category|Product_Name|Product_Price|State|Country| |---|---|---|---|---| |Furniture|Chair|700 Rs|Colordo|US| |Furniture|Bed|2000 Rs|Colordo|US| |Electronics|TV|1200 Rs|Capetown|Africa| |Electronics|Radio|700 Rs|Delhi|India| |Leather|Bag|800 Rs|Mumbai|India| |Garments|Jacket|2300 Rs|Nairobi|Kenya|

Determine the name and total price of product, produced for the specific state. Select the correct option.

  1. SELECT product_name, sum(product_price) FROM product
  2. SELECT product_name, product_price FROM product group by state
  3. SELECT product_name, sum(product_price) FROM product group by state
  4. SELECT sum(product_price) FROM product group by state
  5. None of the above
Question 4 Multiple Choice (Single Answer)

Product Table:

|Category|Product_Name|Product_Price|State|Country| |---|---|---|---|---| |Furniture|Chair|700 Rs|Colordo|US| |Furniture|Bed|2000 Rs|Colordo|US| |Electronics|TV|1200 Rs|Capetown|Africa| |Electronics|Radio|700 Rs|Delhi|India| |Leather|Bag|800 Rs|Mumbai|India| |Garments|Jacket|2300 Rs|Nairobi|Kenya|
  1. SELECT product SET product_name='Jeans' WHERE product_price> 2000
  2. UPDATE product _nameSET product_name='Jeans' WHERE product_price> 2000
  3. UPDATE product SET product_name='Jeans' WHERE product_price> 2000
  4. UPDATE product SET product_name='Jeans' WHERE product_price IN (Select MAX (product_price) from product)
  5. None of the above
Question 5 Multiple Choice (Single Answer)

Which of the following is/are the correct statement is database programming?

  1. A SQL GRANT is a command used to provide access or privileges on the database objects to the users.
  2. A System privileges allows the user to CREATE, ALTER, or DROP the database objects.
  3. The REVOKE command is used to remove the user access rights or privileges to the database objects.
  4. All of the above
  5. Only (1) and (2)
Question 6 Multiple Choice (Single Answer)

Which of the following object privileges is used for stored procedure in a database programming?

  1. INSERT
  2. SELECT
  3. UPDATE
  4. EXECUTE
  5. Both (3) and (4)
Question 7 Multiple Choice (Single Answer)

Student Table:

|Student_ID|First_Name|Last_Name|Subject| |---|---|---|---| |101|Ajit|Sharma|Physics| |102|Ranjit|Singh|Maths| |103|Virat|Kohli|Sport| |104|Suresh|Saxena|Art| |105|Gagan|Chandra|Chemistry|
  1. SELECT student_id, first_name FROM student WHERE subject IN (SELECT first_name FROM student WHERE subject= 'Maths');
  2. SELECT student_id, first_name FROM student WHERE first_name IN (SELECT first_name FROM student WHERE subject= 'Maths');
  3. SELECT student_id, first_name FROM student WHERE student_id IN (SELECT first_name FROM student WHERE subject= 'Maths');
  4. SELECT student_id, first_name FROM student WHERE first_name IN (SELECT student_id FROM student WHERE subject= 'Maths');
  5. None of the above
Question 8 Multiple Choice (Single Answer)

Consider the following two tables:

Student:

|Student_ID|Name|
|---|---|
|101|Ajit|
|102|Ranjit|
|103|Virat|
|104|Suresh|
|105|Gagan|

Mark:

|Student_ID|Total_marks| |---|---| |101|95| |102|91| |103|80| |104|74| |105|69|

Display the students which have marks more than 80.

  1. SELECT a.student_id, a.name, b.total_marks FROM student a, marks b WHERE a.student_id = b.student_id AND total_marks >80;
  2. SELECT a.student_id, a.name, b.total_marks FROM student a, marks b WHERE a.student_id = b.student_id AND a.total_marks >80;
  3. SELECT a.student_id, a.name, b.total_marks FROM student a, marks b WHERE a.student_id = b.student_id AND b.total_marks >80;
  4. SELECT a.student_id, a.name, b.student_id, b.total_marks FROM student a, marks b WHERE a.student_id = b.student_id AND a.total_marks >80;
  5. None of the above
Question 9 Multiple Choice (Single Answer)

Product Table:

|Category|Product_Name|Product_Price|State|Country| |---|---|---|---|---| |Furniture|Chair|700 Rs|Colordo|US| |Furniture|Bed|2000 Rs|Colordo|US| |Electronics|TV|1200 Rs|Capetown|Africa| |Electronics|Radio|700 Rs|Delhi|India| |Leather|Bag|800 Rs|Mumbai|India| |Garments|Jacket|2300 Rs|Nairobi|Kenya|
  1. SELECT product_name, SUM(product_price) FROM product GROUP BY category where SUM(product_price) > 1500
  2. SELECT product_name, SUM(product_price) FROM product GROUP BY category HAVING SUM(product_price) > 1500
  3. SELECT product_name, product_price FROM product GROUP BY category HAVING SUM(product_price) > 1500
  4. SELECT product_name, SUM(product_price) FROM product GROUP BY category HAVING product_price > 1500
  5. None of the above
Question 10 Multiple Choice (Single Answer)

Student Table:

|Student_ID|First_Name|Last_Name|Subject| |---|---|---|---| |101|Ajit|Sharma|Physics| |102|Ranjit|Singh|Maths| |103|Virat|Kohli|Sport| |104|Suresh|Saxena|Art| |105|Gagan|Chandra|Chemistry|
  1. SELECT student_id, first_name, last_name, subject FROM student WHERE subject != 'Chemistry'
  2. SELECT student_id, first_name, last_name, subject FROM student WHERE subject NOT IN ('Chemistry' )
  3. SELECT student_id, first_name, last_name, subject FROM student WHERE subject = 'Chemistry'
  4. Both (1) and (2)
  5. None of the above
Question 11 Multiple Choice (Single Answer)

Student Table:

|Student_ID|First_Name|Last_Name|Subject| |---|---|---|---| |101|Ajit|Sharma|Physics| |102|Ranjit|Singh|Maths| |103|Virat|Kohli|Sport| |104|Suresh|Saxena|Art| |105|Gagan|Chandra|Chemistry|
  1. SELECT student_id, first_name, last_name FROM student Where first_name IN ('Virat', 'Suresh')
  2. SELECT student_id, first_name, last_name FROM student Where first_name Like ('Virat', 'Suresh')
  3. SELECT student_id, first_name, last_name FROM student Where first_name IN ('Virat' and 'Suresh')
  4. SELECT student_id, first_name, last_name FROM student Where first_name EXISTS ('Virat', 'Suresh')
  5. None of the above
Question 12 Multiple Choice (Single Answer)

Consider the following table:

Product Table:

|Category|Product_Name|Product_Price|State|Country| |---|---|---|---|---| |Furniture|Chair|700 Rs|Colordo|US| |Furniture|Bed|2000 Rs|Colordo|US| |Electronics|TV|1200 Rs|Capetown|Africa| |Electronics|Radio|700 Rs|Delhi|India| |Leather|Bag|800 Rs|Mumbai|India| |Garments|Jacket|2300 Rs|Nairobi|Kenya|

Write the SQL query to delete those products, which have price equal to 2000 Rs.

  1. Delete FROM product WHERE product_price =2000;
  2. Delete produce_name, Product_price FROM product WHERE product_price =2000;
  3. Delete Product_price FROM product WHERE product_price =2000;
  4. Delete FROM product WHERE product_price ==2000;
  5. None of the above
Question 13 Multiple Choice (Single Answer)

Consider the following table:

Product Table:

|Category|Product_Name|Product_Price|State|Country| |---|---|---|---|---| |Furniture|Chair|700 Rs|Colordo|US| |Furniture|Bed|2000 Rs|Colordo|US| |Electronics|TV|1200 Rs|Capetown|Africa| |Electronics|Radio|700 Rs|Delhi|India| |Leather|Bag|800 Rs|Mumbai|India| |Garments|Jacket|2300 Rs|Nairobi|Kenya|

Find the details of products which have prices within a range of 1500 and 2500 Rs.

  1. SELECT * FROM product where price>1500 and price<2500
  2. SELECT * FROM product where price>=1500 and price<=2500
  3. SELECT * FROM product where price between 1500 and 2500
  4. Both (2) and (3)
  5. None of the above
Question 14 Multiple Choice (Single Answer)

Student Table:

|Student_ID|First_Name|Last_Name|Subject| |---|---|---|---| |101|Ajit|Sharma|Physics| |102|Ranjit|Singh|Maths| |103|Virat|Kohli|Sport| |104|Suresh|Saxena|Art| |105|Gagan|Chandra|Chemistry|
  1. SELECT * FROM student WHERE first_name LIKE ‘S%’
  2. SELECT * FROM student WHERE name LIKE ‘S%’
  3. SELECT * first_name FROM student WHERE first_name LIKE ‘S%’
  4. SELECT * FROM student WHERE first_name LIKE ‘S’
  5. None of the above
Question 15 Multiple Choice (Single Answer)

Consider the following table:

Product Table:

|Category|Product_Name|Product_Price|State|Country| |---|---|---|---|---| |Furniture|Chair|700 Rs|Colordo|US| |Furniture|Bed|2000 Rs|Colordo|US| |Electronics|TV|1200 Rs|Capetown|Africa| |Electronics|Radio|700 Rs|Delhi|India| |Leather|Bag|800 Rs|Mumbai|India| |Garments|Jacket|2300 Rs|Nairobi|Kenya|

WAQ to find the details of products whose price is not equal to 2000.

  1. SELECT * FROM product WHERE NOT product_price=2000
  2. SELECT * FROM product WHERE product_price!=2000
  3. SELECT * FROM product WHERE EXCEPT product_price=2000
  4. Both (1) and (2)
  5. (1), (2) and (3) all are true
Question 16 Multiple Choice (Single Answer)

Student Table:

|Student_ID|First_Name|Last_Name|Subject| |---|---|---|---| |101|Ajit|Sharma|Physics| |102|Ranjit|Singh|Maths| |103|Virat|Kohli|Sport| |104|Suresh|Saxena|Art| |105|Gagan|Chandra|Chemistry|
  1. SELECT * FROM student WHERE subject != ’physics’ and subject != ’maths’
  2. SELECT * FROM student WHERE subject != ’physics’, subject != ’maths’
  3. SELECT * FROM student WHERE subject NOT IN (’physics’, ’maths’)
  4. Both (1) and (3)
  5. None of the above
Question 17 Multiple Choice (Single Answer)

Student Table:

|Student_ID|First_Name|Last_Name|Subject| |---|---|---|---| |101|Ajit|Sharma|Physics| |102|Ranjit|Singh|Maths| |103|Virat|Kohli|Sport| |104|Suresh|Saxena|Art| |105|Gagan|Chandra|Chemistry|
  1. SELECT * FROM student WHERE subject=’Maths’ OR subject='Physics’ OR subject=’sport’
  2. SELECT * FROM student WHERE subject IN (’Maths’, ’Physics’, ’sport’)
  3. SELECT * FROM student WHERE subject=’Maths’, subject='Physics’, subject=’sport’
  4. Both (1) and (2)
  5. Both (2) and (3)