Computer Knowledge

Database and SQL

3,929 Questions

Master structured query language commands, database joins, table constraints, and alias generation. This section covers relational database management concepts and query outputs essential for technical aptitude. These technical questions feature prominently in banking IT officer exams and computer knowledge sections.

SQL queries and aliasesDatabase table constraintsDatabase joins and transformationsStored procedures and functions

Database and SQL Questions

Multiple choice
  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

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

This is the correct SQL query for the specified result.

Multiple choice
  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

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

This is a correct query for specified result.

Multiple choice
  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

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

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

Multiple choice
  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

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

This is the correct query for the desired result.

Multiple choice
  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

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Both will produce desired result.

Multiple choice
  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

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This is a correct query for the specified result.

Multiple choice
  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

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This is the correct syntax for the desired result.

Multiple choice
  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

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Yes, both are applicable for the desired result.

Multiple choice
  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

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This is correct SQL query to get specified records.

Multiple choice
  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

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

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

Multiple choice
  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

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Both are the correct queries.

Multiple choice
  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)

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Both are applicable for the specific result.