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

Multiple choice .net
  1. Every table should have a primary key.

  2. A primary key exclusively identifies each row in a table.

  3. A primary key can be made of multiple fields.

  4. Both a and b.

  5. All of the above.

Reveal answer Fill a bubble to check yourself
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.

Multiple choice .net
  1. has nothing to do with the primary key.

  2. has different values than the primary key.

  3. is found in tables that don’t have a primary key.

  4. is related to the primary key of a different table.

  5. is a unique record in a table.

Reveal answer Fill a bubble to check yourself
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.

Multiple choice .net
  1. 1

  2. 2

  3. 3

  4. As many as needed.

Reveal answer Fill a bubble to check yourself
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.

Multiple choice .net
  1. LEFT JOIN

  2. MIDDLE JOIN

  3. RIGHT JOIN

  4. INNER JOIN

  5. All of the above are valid types.

Reveal answer Fill a bubble to check yourself
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.

Multiple choice .net
  1. fields.

  2. records.

  3. tables.

  4. Both a and b.

  5. All of the above.

Reveal answer Fill a bubble to check yourself
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.

Multiple choice database
  1. GRANT ALL PRIVILEGES WHERE FROM ON TO

  2. GRANT ALL PRIVILEGES TO WHERE FROM

  3. GRANT ALL PRIVILEGES WHERE FROM TO

  4. GRANT ALL PRIVILEGES ON TO

  5. GRANT ALL PRIVILEGES ON WHERE FROM

Reveal answer Fill a bubble to check yourself
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.

Multiple choice database
  1. Fixed length string of n characters

  2. Variable length string up to n characters

  3. Floating point number of p bits precision

  4. 16-bit signed integer

  5. 32-bit signed integer

Reveal answer Fill a bubble to check yourself
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.

Multiple choice database
  1. DUBPLICATE

  2. INDIVIDUAL

  3. SEPARATE

  4. DISTINCT

  5. INDEX

Reveal answer Fill a bubble to check yourself
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.

Multiple choice database
  1. DROP SCHEMA CASCADE

  2. DROP SCHEMA RESTRICT

  3. DROP SCHEMA ALL

  4. DROP SCHEMA CLEAR

  5. DROP SCHEMA OPTS

Reveal answer Fill a bubble to check yourself
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.

Multiple choice database
  1. CREATE SCHEMA

  2. CREATE TABLE

  3. CREATE DOMAIN

  4. CREATE INDEX

  5. All of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice database
  1. DROP SCHEMA RESTRICT

  2. DROP SCHEMA OPTS

  3. DROP SCHEMA CASCADE

  4. DROP SCHEMA CLEAR

Reveal answer Fill a bubble to check yourself
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.