0

SQL Programming Language

Description: This test consists of questions related to SQL queries and programming, which is useful for CS and Gate students.
Number of Questions: 17
Created by:
Tags: SQL database CS Gate SQL questions Database questions practice DB interview questions Database
Attempted 0/17 Correct 0 Score 0

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


Correct Option: D
Explanation:

Both are the correct queries.

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


Correct Option: A
Explanation:

This is example of equi-join as it has equal operator.

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


Correct Option: C
Explanation:

This is a correct SQL query for the specified result.

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


Correct Option: C
Explanation:

This is the correct SQL query for the specified result.

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)


Correct Option: D
Explanation:

Yes, all are correct.

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)


Correct Option: D
Explanation:

This object privileges allows user to execute a stored procedure or a function.

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


Correct Option: B
Explanation:

This is a correct query for specified result.

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


Correct Option: C
Explanation:

This is a correct query as we are joining the two tables to match their Ids and then displaying the desired result.

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


Correct Option: B
Explanation:

This is the correct query for the desired result.

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


Correct Option: D
Explanation:

Both will produce desired result.

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


Correct Option: A
Explanation:

This is a correct query for the specified result.

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


Correct Option: A
Explanation:

This is the correct syntax for the desired result.

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


Correct Option: D
Explanation:

Yes, both are applicable for the desired result.

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


Correct Option: A
Explanation:

This is correct SQL query to get specified records.

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


Correct Option: D
Explanation:

Yes, both are the correct queries to fetch specified records.

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


Correct Option: D
Explanation:

Both are the correct queries.

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)


Correct Option: D
Explanation:

Both are applicable for the specific result.

- Hide questions