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

  2. Stored Function

  3. Stored Procedure

  4. Another Trigger

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

A CALL statement within a database trigger is used to invoke stored procedures. Triggers can execute stored procedures to perform complex operations that cannot be done with simple SQL statements. Packages are schema objects that group related procedures, functions, and variables, while stored functions return values and cannot be called with CALL in most database systems.

Multiple choice technology databases
  1. VARCHAR2

  2. BOOLEAN

  3. IN

  4. OUT

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

OUT parameters are specifically designed to pass values back from a procedure to the calling environment. IN parameters pass values into the procedure but cannot return values. VARCHAR2 and BOOLEAN are data types, not parameter modes. The OUT mode allows the procedure to send computed results back to the caller.

Multiple choice technology architecture
  1. Using aliases

  2. Removing extra joins

  3. Using Contexts

  4. A loop cannot be removed

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

Loops in universe schema design occur when multiple join paths exist between tables. Aliases create alternate table references to break loops by providing unique paths. Contexts define separate logical paths for different query scenarios. Option B is incorrect because removing joins would break required relationships.

Multiple choice technology databases
  1. (a) Use the bcp command

  2. (b) Use the BULKINSERT statement

  3. (c) Create a custom format file

  4. (d) None of the above

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

The bcp (Bulk Copy Program) utility is specifically designed for bulk importing data from text files into SQL Server. It's a command-line tool optimized for high-volume data transfer and handles various text formats. BULK INSERT is a T-SQL statement that performs similar function but requires the file to be accessible from the server. Both are valid, but bcp is the most direct answer for 'receiving text files' that need import. Custom format files are used with both bcp and BULK INSERT to define column mappings, not a standalone solution.

Multiple choice technology databases
  1. (a) Text

  2. (b) Varbinary

  3. (c) Varchar(max)

  4. (d) Varchar

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

VARCHAR(max) is the correct data type for storing up to 2 GB of text in SQL Server 2005. The TEXT data type is deprecated and doesn't support standard string functions and operators directly - you need to use READTEXT/WRITETEXT. VARCHAR(max) allows you to use all standard string functions and operators. VARCHAR without (max) has a maximum of 8000 characters. VARBINARY(max) is for binary data, not text.

Multiple choice technology databases
  1. (a) UNION

  2. (b) SCHEMABINDING

  3. (c) CHECK OPTION

  4. (d) All

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

SCHEMABINDING on a view or function creates a dependency that prevents dropping the underlying tables. When an object is schema-bound, SQL Server ensures the object's definition remains valid by blocking any changes to referenced schema elements. This means you cannot DROP a table that a schema-bound view references - you must first drop or alter the schema-bound object. UNION and CHECK OPTION are view options that don't prevent dropping tables.

Multiple choice technology databases
  1. (a) SCHEMABINDING

  2. (b) CHECK OPTION

  3. (c) ANSI_NULLS

  4. (d) All

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

CHECK OPTION is a view option that ensures any INSERT or UPDATE operation through the view must satisfy the view's defining query criteria. This prevents data modifications that would make the rows invisible to the view itself. SCHEMABINDING is specific to SQL Server and binds objects to the schema, while ANSI_NULLS controls NULL comparison behavior.

Multiple choice technology databases
  1. (a) Full outer join

  2. (b) Inner join

  3. (c) Right outer join

  4. (d) Left outer join

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

Outer joins (left, right, and full) are designed to retrieve non-matching rows from one or both tables, filling missing columns with NULLs. An inner join only returns rows where there is a match in both tables.

Multiple choice technology databases
  1. (a) AS

  2. (b) STR

  3. (c) FROM

  4. (d) COLUMN

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

The AS keyword is used in SQL to create column aliases, which provide temporary alternate names for columns in query results. This improves readability and is especially useful when using calculated expressions or aggregate functions. STR, FROM, and COLUMN are not used for aliasing purposes.

Multiple choice technology databases
  1. A. SELECT TO CHAR(8000,’$#,###.##’) FROM DUAL;
  2. B. SELECT TO CHAR(8000,’$0,000.00’) FROM DUAL;
  3. C. SELECT TO CHAR(8000,’$9,999.00’) FROM DUAL;
  4. D. SELECT TO CHAR(8000,’$9,999.99’) FROM DUAL;
  5. E. SELECT TO CHAR(8000,’$8,000.00’) FROM DUAL;
  6. F. SELECT TO CHAR(8000,’$N,NNN.NN’) FROM DUAL;
Reveal answer Fill a bubble to check yourself
B,C,D Correct answer
Explanation

In Oracle SQL, TO_CHAR format models use 0 and 9 as digit placeholders. 0 displays leading zeros, while 9 displays significant digits only. For 8000 to display as '\$8,000.00', we need at least one digit placeholder for the thousands place and two for decimals. Options B, C, and D all achieve this with '\$0,000.00', '$9,999.00', and '$9,999.99' respectively - the last option shows decimal places even if zero. Options A and F use incorrect format syntax.

Multiple choice technology databases
  1. At the beginning of the list

  2. At the end of the list

  3. In the middle of the list

  4. At the same location they are listed in the unordered table

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

When sorting in descending order (DESC), NULL values appear at the beginning of the result set in Oracle SQL, opposite to their placement in ascending sorts. This is consistent with Oracle's treatment of NULL as greater than any non-NULL value. The NULL records do not appear in the middle or retain their original table positions.

Multiple choice technology databases
  1. The DESCRIBE DEPT statement returns an error ORA-04043: object DEPT does not exist

  2. The ROLLBACK statement frees the storage space occupies by the DEPT table

  3. The DESCRIBE DEPT statement displays the structure of the DEPT table

  4. The DESCRIBE DEPT statement displays the structure of the DEPT table only if there is a COMMIT statement introduced before the ROLLBACK statement

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

DDL statements like CREATE TABLE perform an implicit COMMIT in Oracle. Therefore, the DEPT table is permanently created before the ROLLBACK executes, making ROLLBACK ineffective. The subsequent DESCRIBE DEPT command succeeds and displays the table structure. Option A is incorrect because the table exists, B is incorrect because ROLLBACK cannot undo DDL, and D is incorrect because no explicit COMMIT is needed.

Multiple choice technology databases
  1. USER_TAB_PRIVS_MADE

  2. USER_TAB_PRIVS

  3. USER_COL_PRIVS_MADE

  4. USER_COL_PRIVS

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

Oracle's USER_COL_PRIVS data dictionary view lists column-level object privileges granted to the current user. USER_TAB_PRIVS shows table-level privileges, while _MADE views show privileges granted on objects owned by the user rather than privileges granted to them.

Multiple choice technology databases
  1. The SQL statement displays the desired results

  2. The operator in the WHERE clause should be changed to display the desired results

  3. The WHERE clause should be changed to use an outer join to display the desired results

  4. The column in the WHERE clause should be changed to display the desired results

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

The SQL statement uses DEPARTMENT_ID = NULL, which is incorrect because NULL requires the IS NULL or IS NOT NULL operators. The equality operator (=) always returns NULL (not TRUE or FALSE) when comparing with NULL, so no rows are selected. The correct syntax is WHERE DEPARTMENT_ID IS NULL. Options A, C, and D are incorrect - the operator itself needs to change, not the column name, and outer joins are not needed here.