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
-
Select all columns from EMP;
-
Select distinct columns from EMP;
-
Select * from EMP;
-
All of the above
C
Correct answer
Explanation
SELECT * from EMP; is the correct SQL syntax to select all columns. The asterisk (*) wildcard represents all columns in the table.
B
Correct answer
Explanation
This statement will fail due to syntax errors: there are extra spaces (select, ename, emp) and the string literal Scott is not properly quoted with single quotes. SQL requires single quotes for string literals.
-
Structured Query Language
-
Standard Query Language
-
System Query Language
-
Simple Query Language
A
Correct answer
Explanation
SQL stands for Structured Query Language, which is the standard language for relational database management systems. It's used for querying, manipulating, and defining data in databases.
-
Distinct
-
Projection
-
Where
-
All of the above
C
Correct answer
Explanation
This is an exact duplicate of question 139501. The WHERE clause filters rows based on specified conditions. DISTINCT removes duplicates and projection selects columns.
-
Projection
-
Selection
-
Join
-
All of the above
D
Correct answer
Explanation
The SQL SELECT statement possesses three primary capabilities: selection, which filters rows using a WHERE clause; projection, which chooses specific columns to display; and joining, which combines data from multiple tables. Therefore, all of the listed capabilities are correct.
-
Select all columns from EMP;
-
Select distinct columns from EMP;
-
Select * from EMP;
-
All of the above
C
Correct answer
Explanation
This is an exact duplicate of question 139506. SELECT * from EMP; is correct syntax where * selects all columns from the EMP table.
B
Correct answer
Explanation
In standard SQL, character literals must be enclosed in single quotes ('Scott'). Double quotes are reserved for database identifiers like table or column names. Using double quotes for a string literal causes a compilation or execution error, making the statement false.
-
Structured Query Language
-
Standard Query Language
-
System Query Language
-
Simple Query Language
A
Correct answer
Explanation
SQL stands for Structured Query Language, which is the standard programming language used to manage and manipulate relational databases. The other options, such as Standard, System, or Simple Query Language, are incorrect expansions of the acronym and do not represent the official name.
-
Duplicate
-
Distinct
-
Remove
-
Delete
B
Correct answer
Explanation
In SQL, the DISTINCT keyword is used in SELECT statements to remove duplicate rows from the result set, returning only unique values. While options like 'Duplicate', 'Remove', and 'Delete' might seem conceptually related, they are not valid SQL keywords for this purpose. DISTINCT is the standard SQL operator specifically designed for eliminating duplicate values.
-
Single-row subquery, Double-row subquery
-
Double-row subquery, Multiple-row subquery
-
Multiple-row subquery
-
Single-row subquery and Multiple subquery
D
Correct answer
Explanation
Subqueries are broadly classified based on the number of rows they return to the outer query. Single-row subqueries return only one row, whereas multiple-row subqueries return one or more rows. The other options incorrectly include non-existent concepts like double-row subqueries.
-
Only one row
-
Two rows
-
Zero rows
-
There is no such subquery
A
Correct answer
Explanation
A single-row subquery is designed to return exactly one row and one column. This type of subquery is typically used with single-row comparison operators like =, >, <, >=, or <=. If a single-row subquery returns more than one row, it will cause an error, and if it returns no rows, the result is null.
-
It gives the name and marks of all the students.
-
It does not return anything.
-
It shows an error saying” INVALID SYNTAX ERROR”
-
It shows an error saying” Single-row subquery returns more than one row
D
Correct answer
Explanation
The subquery groups by Rollnum, returning the minimum marks for each group, which results in multiple rows. Because the outer query uses the single-value comparison operator =, it fails with a 'single-row subquery returns more than one row' error. Other options are incorrect as the query cannot execute successfully.
C
Correct answer
Explanation
The ALL operator in SQL compares a value to every value returned by a subquery, evaluating to true only if the comparison is true for all values. For example, 'salary > ALL (subquery)' returns true only if the salary is greater than every single value returned by the subquery. IN checks membership, ANY returns true if at least one comparison succeeds, and OF is not a valid SQL operator.
-
Add new rows to a table
-
Modify existing rows of a table
-
Remove existing rows from a table
-
All of the above
D
Correct answer
Explanation
DML (Data Manipulation Language) statements include INSERT (adding new rows), UPDATE (modifying existing rows), and DELETE (removing existing rows). Since all three operations are fundamental DML operations, option D is correct as it encompasses all the individual DML actions listed in the other options.
-
Insert to table tablename (….);
-
Insert into table tablename (….);
-
Insert into table tablename values (…..);
-
Any one of the above
C
Correct answer
Explanation
The correct SQL syntax for inserting values is 'INSERT INTO tablename VALUES (...)' which directly inserts values into a table. Options A and B have incorrect syntax ('Insert to' and 'insert into table' are not valid). Option C correctly shows 'Insert into table tablename values' though it would typically be 'INSERT INTO tablename VALUES' without the word 'table' - but among the given choices, C is the closest to correct syntax.