Computer Knowledge
Database and SQL
4,213 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
-
Every table should have a primary key.
-
A primary key exclusively identifies each row in a table.
-
A primary key can be made of multiple fields.
-
Both a and b.
-
All of the above.
E
Correct answer
Explanation
A primary key is essential for database integrity and should be present in every table. It uniquely identifies each row, preventing duplicate records, and can consist of multiple fields for composite keys when a single field is insufficient.
-
has nothing to do with the primary key.
-
has different values than the primary key.
-
is found in tables that don’t have a primary key.
-
is related to the primary key of a different table.
-
is a unique record in a table.
D
Correct answer
Explanation
A foreign key is a column or group of columns in one table that provides a link between data in two tables. It acts as a cross-reference by pointing to the primary key of another table, thereby enforcing referential integrity.
-
JOIN
-
ON
-
ORDER BY
-
SELECT
-
WHERE
D
Correct answer
Explanation
The SELECT clause is the fundamental requirement for any SQL query intended to retrieve data. While WHERE, ORDER BY, and JOIN are common for filtering and organizing, they are optional; a valid query must start with SELECT to identify the data to be fetched.
D
Correct answer
Explanation
SQL's SELECT clause has no limitation on the number of fields specified. You can select one field, multiple fields, or all fields in a single query depending on your requirements.
D
Correct answer
Explanation
The SELECT clause specifies which columns (fields) to retrieve, not the number of records. The number of records returned is determined by the WHERE clause and the data present in the table. Thus, it can return as many records as match the criteria.
D
Correct answer
Explanation
The asterisk (*) is the standard SQL wildcard character used in SELECT statements to retrieve all columns from a table. It saves listing individual field names when you need complete row data.
-
fields
-
records
-
tables
-
Both a and b.
-
All of the above.
B
Correct answer
Explanation
The WHERE clause filters records returned by SQL queries based on specified conditions. It restricts the result set to only those rows that meet the criteria, reducing output to relevant records.
-
LEFT JOIN
-
MIDDLE JOIN
-
RIGHT JOIN
-
INNER JOIN
-
All of the above are valid types.
B
Correct answer
Explanation
SQL supports INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, and CROSS JOIN as valid join types. MIDDLE JOIN is not a standard SQL join type and does not exist in SQL syntax.
-
fields.
-
records.
-
tables.
-
Both a and b.
-
All of the above.
B
Correct answer
Explanation
The ORDER BY clause in SQL is used to specify the sequence in which the resulting records (rows) are returned. While it uses field names to determine the sort criteria, the actual items being sorted and rearranged in the output are the records themselves.
-
GRANT ALL PRIVILEGES WHERE FROM ON TO
-
GRANT ALL PRIVILEGES TO WHERE FROM
-
GRANT ALL PRIVILEGES WHERE FROM TO
-
GRANT ALL PRIVILEGES ON TO
-
GRANT ALL PRIVILEGES ON WHERE FROM
D
Correct answer
Explanation
The correct SQL syntax for granting privileges is GRANT [privileges] ON [object] TO [user]. Option D follows this structure correctly with placeholders for the relation name and username. Options A, B, C, and E have the keywords WHERE and FROM in wrong positions - WHERE and FROM are clauses used in SELECT/UPDATE queries, not in GRANT statements.
-
Fixed length string of n characters
-
Variable length string up to n characters
-
Floating point number of p bits precision
-
16-bit signed integer
-
32-bit signed integer
B
Correct answer
Explanation
VARCHAR stores variable-length character strings up to a maximum of n characters. Unlike CHAR which is fixed-length, VARCHAR only uses storage for the actual characters entered plus length information. Options C, D, and E describe numeric data types (floating point and integers), not character types.
-
DUBPLICATE
-
INDIVIDUAL
-
SEPARATE
-
DISTINCT
-
INDEX
D
Correct answer
Explanation
The DISTINCT keyword in SQL is used within a SELECT statement to filter out duplicate rows from the result set, returning only unique values. Keywords like 'INDIVIDUAL' or 'SEPARATE' are not valid SQL syntax for this purpose.
-
DROP SCHEMA CASCADE
-
DROP SCHEMA RESTRICT
-
DROP SCHEMA ALL
-
DROP SCHEMA CLEAR
-
DROP SCHEMA OPTS
A
Correct answer
Explanation
The CASCADE option in a DROP SCHEMA statement instructs the database to remove the schema along with all of its contained objects (tables, views, etc.) in one operation. RESTRICT would prevent the deletion if any objects still existed within that schema.
-
CREATE SCHEMA
-
CREATE TABLE
-
CREATE DOMAIN
-
CREATE INDEX
-
All of the above
E
Correct answer
Explanation
All four statements are valid DDL (Data Definition Language) commands. CREATE SCHEMA defines a namespace, CREATE TABLE defines table structure, CREATE DOMAIN defines a custom data type, and CREATE INDEX builds an index. DDL commands define database structures, not manipulate data.
-
DROP SCHEMA RESTRICT
-
DROP SCHEMA OPTS
-
DROP SCHEMA CASCADE
-
DROP SCHEMA CLEAR
A
Correct answer
Explanation
The RESTRICT keyword in a DROP SCHEMA statement ensures that the schema is only deleted if it contains no objects. If the schema is not empty, the command will fail. In contrast, CASCADE would delete the schema and all objects within it automatically.