SQL Programming Language
This test consists of questions related to SQL queries and programming, which is useful for CS and Gate students.
Questions
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.
- SELECT product_name FROM product WHERE country= 'US'
- SELECT product_name FROM product WHERE product_name IN (SELECT product_name FROM Product WHERE country= US)
- SELECT product_name FROM product WHERE product_name IN (SELECT product_name FROM Product WHERE country= 'US')
- Both (1) and (3)
- None of the above
Which of the following SQL query is the example of equi join?
- SELECT first_name, last_name, subject FROM student_details WHERE subject = 'Economics'
- SELECT first_name, last_name, subject FROM student_details WHERE marks>90
- SELECT first_name, last_name, subject FROM student_details WHERE marks=>90
- Both (1) and (3)
- None of the above
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.
- SELECT product_name, sum(product_price) FROM product
- SELECT product_name, product_price FROM product group by state
- SELECT product_name, sum(product_price) FROM product group by state
- SELECT sum(product_price) FROM product group by state
- None of the above
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|- SELECT product SET product_name='Jeans' WHERE product_price> 2000
- UPDATE product _nameSET product_name='Jeans' WHERE product_price> 2000
- UPDATE product SET product_name='Jeans' WHERE product_price> 2000
- UPDATE product SET product_name='Jeans' WHERE product_price IN (Select MAX (product_price) from product)
- None of the above
Which of the following is/are the correct statement is database programming?
- A SQL GRANT is a command used to provide access or privileges on the database objects to the users.
- A System privileges allows the user to CREATE, ALTER, or DROP the database objects.
- The REVOKE command is used to remove the user access rights or privileges to the database objects.
- All of the above
- Only (1) and (2)
Which of the following object privileges is used for stored procedure in a database programming?
- INSERT
- SELECT
- UPDATE
- EXECUTE
- Both (3) and (4)
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|- SELECT student_id, first_name FROM student WHERE subject IN (SELECT first_name FROM student WHERE subject= 'Maths');
- SELECT student_id, first_name FROM student WHERE first_name IN (SELECT first_name FROM student WHERE subject= 'Maths');
- SELECT student_id, first_name FROM student WHERE student_id IN (SELECT first_name FROM student WHERE subject= 'Maths');
- SELECT student_id, first_name FROM student WHERE first_name IN (SELECT student_id FROM student WHERE subject= 'Maths');
- None of the above
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.
- 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;
- 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;
- 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;
- 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;
- None of the above
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|- SELECT product_name, SUM(product_price) FROM product GROUP BY category where SUM(product_price) > 1500
- SELECT product_name, SUM(product_price) FROM product GROUP BY category HAVING SUM(product_price) > 1500
- SELECT product_name, product_price FROM product GROUP BY category HAVING SUM(product_price) > 1500
- SELECT product_name, SUM(product_price) FROM product GROUP BY category HAVING product_price > 1500
- None of the above
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|- SELECT student_id, first_name, last_name, subject FROM student WHERE subject != 'Chemistry'
- SELECT student_id, first_name, last_name, subject FROM student WHERE subject NOT IN ('Chemistry' )
- SELECT student_id, first_name, last_name, subject FROM student WHERE subject = 'Chemistry'
- Both (1) and (2)
- None of the above
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|- SELECT student_id, first_name, last_name FROM student Where first_name IN ('Virat', 'Suresh')
- SELECT student_id, first_name, last_name FROM student Where first_name Like ('Virat', 'Suresh')
- SELECT student_id, first_name, last_name FROM student Where first_name IN ('Virat' and 'Suresh')
- SELECT student_id, first_name, last_name FROM student Where first_name EXISTS ('Virat', 'Suresh')
- None of the above
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.
- Delete FROM product WHERE product_price =2000;
- Delete produce_name, Product_price FROM product WHERE product_price =2000;
- Delete Product_price FROM product WHERE product_price =2000;
- Delete FROM product WHERE product_price ==2000;
- None of the above
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.
- SELECT * FROM product where price>1500 and price<2500
- SELECT * FROM product where price>=1500 and price<=2500
- SELECT * FROM product where price between 1500 and 2500
- Both (2) and (3)
- None of the above
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|- SELECT * FROM student WHERE first_name LIKE ‘S%’
- SELECT * FROM student WHERE name LIKE ‘S%’
- SELECT * first_name FROM student WHERE first_name LIKE ‘S%’
- SELECT * FROM student WHERE first_name LIKE ‘S’
- None of the above
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.
- SELECT * FROM product WHERE NOT product_price=2000
- SELECT * FROM product WHERE product_price!=2000
- SELECT * FROM product WHERE EXCEPT product_price=2000
- Both (1) and (2)
- (1), (2) and (3) all are true
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|- SELECT * FROM student WHERE subject != ’physics’ and subject != ’maths’
- SELECT * FROM student WHERE subject != ’physics’, subject != ’maths’
- SELECT * FROM student WHERE subject NOT IN (’physics’, ’maths’)
- Both (1) and (3)
- None of the above
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|- SELECT * FROM student WHERE subject=’Maths’ OR subject='Physics’ OR subject=’sport’
- SELECT * FROM student WHERE subject IN (’Maths’, ’Physics’, ’sport’)
- SELECT * FROM student WHERE subject=’Maths’, subject='Physics’, subject=’sport’
- Both (1) and (2)
- Both (2) and (3)