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 technology databases
  1. True

  2. False

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

You can call a stored procedure from an anonymous PL/SQL block. Anonymous blocks can invoke procedures using the EXECUTE statement or direct procedure calls. This is a standard way to test or execute procedures without creating a named stored block. The procedure executes within the block's scope.

Multiple choice technology databases
  1. Copy table

  2. Alter table

  3. Export table

  4. Generate DDL

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

DDL (Data Definition Language) contains the SQL commands that define database structures like CREATE TABLE. Generating DDL allows you to duplicate table structure along with constraints and indexes. Copy/Alter/Export table operate on data, not structure.

Multiple choice technology databases
  1. Both are True

  2. i) Is Only True

  3. ii) is only True

  4. Neither is True

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

A cursor must always be opened before fetching rows. In standard embedded SQL, each execution of the FETCH statement retrieves exactly one row into host variables. Both statements are true, making the selected option correct.

Multiple choice technology databases
  1. Same value of Primary Key can appear in more than one row in the table

  2. A Primary key defined column can be of type LONG

  3. A column that is defined as Primary Key cannot contain NULL value.

  4. Both A. and B.

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

By definition, a primary key uniquely identifies each row in a table and therefore cannot contain NULL values. NULL would violate the uniqueness constraint since NULL = NULL is not true in SQL. Option A is false because primary key values must be unique. Option B is incorrect because LONG is not a standard SQL data type (though CLOB/BLOB exist).

Multiple choice technology databases
  1. Using a view to access the table

  2. Using a referential constraint on the table

  3. Revoking access from the phone_number column

  4. Defining a table check constraint on the table

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

A view is a virtual table that can restrict access to specific columns. By creating a view that excludes the phone_number column and granting users access only to the view (not the base table), you effectively limit their read access. Referential constraints enforce relationships between tables, revoking access from a column doesn't work as columns are accessed through the table, and check constraints validate data values.

Multiple choice technology databases
  1. ON DELETE RESTRICT

  2. ON DELETE CASCADE

  3. ON DELETE SET NULL

  4. ON DELETE CHILD

  5. ON DELETE MATCH

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

ON DELETE CASCADE automatically deletes all matching rows in the child table (T2) when the referenced row in the parent table (T1) is deleted. RESTRICT prevents deletion if child rows exist, SET NULL sets the foreign key to NULL, and CHILD and MATCH are not standard ON DELETE options.

Multiple choice technology databases
  1. forces cursor to close after commit

  2. Keeps cursor open after commit

  3. Does not allow cursor to close till all rows are fetched

  4. Locks the cursor

  5. None of the above

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

The WITH HOLD option in DB2 (and other RDBMS) keeps a cursor open across COMMIT operations. Without WITH HOLD, the cursor would close automatically when a COMMIT is issued. It doesn't force closure, lock the cursor, or wait for all rows to be fetched.

Multiple choice technology databases
  1. EQUI-JOIN

  2. NON EQUI-JOIN

  3. Both A. and B.

  4. None of the Above

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

SQL supports both EQUI-JOIN (joining using equality operator) and NON-EQUI-JOIN (joining using operators other than =, such as <, >, BETWEEN, etc.). An EQUI-JOIN is a join condition using =, while NON-EQUI-JOIN uses any other comparison operator.

Multiple choice technology databases
  1. 100 rows

  2. 50 rows

  3. 150 rows

  4. 5000 rows

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

When joining two tables without a WHERE clause specifying the join condition, you get a Cartesian product (cross join). Every row in T1 pairs with every row in T2, so 100 rows x 50 rows = 5000 rows. This is a common SQL mistake that produces much more data than intended.

Multiple choice technology databases
  1. ALTER TABLE command is used to create a table

  2. ALTER TABLE command is used to change the column elements in a table

  3. ALTER TABLE command is used to delete a table

  4. Both A. and C.

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

The ALTER TABLE command is used to modify the structure of an existing table (like changing columns), not to create (CREATE TABLE) or delete (DROP TABLE) a table. Therefore, both A and C are false statements about ALTER TABLE, making this option correct.

Multiple choice technology databases
  1. Unique constraints

  2. Primary keys

  3. Cascading actions

  4. Foreign keys

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

Referential integrity maintains relationships between tables via foreign keys and primary keys. Unique constraints ensure column uniqueness within a single table but don't enforce relationships between tables. Cascading actions (like CASCADE delete) and foreign keys directly maintain referential integrity, while primary keys define the parent side of the relationship.

Multiple choice technology databases
  1. Cursors

  2. Host Variables

  3. Indicator Variable

  4. SQLCA

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

Cursors are SQL memory structures that point to a result set and allow the application to process multiple rows one at a time. Host variables, indicator variables, and the SQLCA (SQL Communication Area) are used for data exchange, null handling, and error checking, not row iteration.

Multiple choice technology enterprise content management
  1. Table affects the relativity of below table.

  2. Table does not affects the relativity any object.

  3. Table does not affect any object and the table moves to a new page based on rule given

  4. Table does not affect any object and the table moves to a new page always

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

When a table is set to break flow on a page, it moves to a new page and does not affect the positioning or flow of any objects that come after it. This creates a page break at that table's location regardless of other layout rules. Option C incorrectly suggests the move is rule-based.

Multiple choice technology
  1. convert(varchar(10), sys_date,101)

  2. convert(varchar(11), sys_date)

  3. convert(varchar(10), sys_date)

  4. cast(sys_date as varchar(11))

Reveal answer Fill a bubble to check yourself
A,B,D Correct answer
Explanation

CONVERT function in SQL Server can convert datetime to varchar with optional style codes. CONVERT(varchar(10), sys_date, 101) converts to mm/dd/yyyy format (style 101). CONVERT(varchar(11), sys_date) converts without style (default format). CAST(sys_date as varchar(11)) is equivalent to CONVERT without style. Option C is incomplete - it needs a style parameter or length specification to be syntactically correct for this use case.