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
C
Correct answer
Explanation
The hyphen (-) character in SQL*Plus allows you to break long SQL statements across multiple lines. When placed at the end of a line, it signals that the statement continues on the next line. The forward slash (/) is used to execute the current buffer, not for continuation.
-
03-JUL-00
-
10-JUL-00
-
12-JUL-00
-
11-JUL-00
-
17-JUL-00
E
Correct answer
Explanation
The NEXT_DAY function returns the first occurrence of a specified weekday that comes AFTER the current date. Since today is Monday, July 10, NEXT_DAY looks for the NEXT Monday, which is July 17. It doesn't return the current day, but the following instance of that weekday.
-
8
-
2
-
3
-
4
-
THERE IS NO SUCH CRITERIA
C
Correct answer
Explanation
When joining n tables in Oracle (or most SQL databases), you need at least n-1 join conditions to avoid Cartesian products between the tables. For 4 tables, this means at least 3 join conditions. Each condition links one table to another, creating a chain that connects all tables.
A
Correct answer
Explanation
The SQL concatenation operator || joins multiple column values into a single result column. This query combines name, age, and address with comma separators, creating exactly one output column named 'emp_details'. The number of source columns concatenated doesn't affect the result column count.
-
Full table scan
-
Table access by ROWID
-
Access via unique index
-
Primary key access
B
Correct answer
Explanation
Accessing a row by its physical address (ROWID) is the fastest access path in Oracle. It allows Oracle to locate the row directly on disk in a single read. Other methods like index lookups or primary key access require searching the index structure first to find the ROWID.
-
DROP
-
TRUNCATE
-
DELETE
-
CASCADE
B
Correct answer
Explanation
The TRUNCATE command is a DDL statement that removes all rows from a table immediately. Because it is DDL, it commits automatically and does not write individual row deletes to the rollback segment, making it faster than DELETE. DROP deletes the table structure entirely.
A
Correct answer
Explanation
The MAX function can operate on any standard datatype (numeric, character, or date/time). Functions like TO_CHAR require specific input types (typically numeric or date), LOWER operates only on character data, and CEIL works exclusively with numeric values.
-
Row level DML trigger
-
Statement level DML trigger
-
Row level Application trigger
-
Statement level Application trigger
A
Correct answer
Explanation
OLD and NEW qualifiers (referencing :OLD and :NEW values) are only available in row-level DML triggers. These qualifiers reference the before/after state of the row being modified. Statement-level triggers operate on sets of rows and don't have :OLD/:NEW context. Application triggers (Forms/Reports) have different mechanisms.
-
Package
-
Stored Function
-
Stored Procedure
-
Another Trigger
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.
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.
-
Using aliases
-
Removing extra joins
-
Using Contexts
-
A loop cannot be removed
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.
A
Correct answer
Explanation
SQL Server 2005 supports renaming databases and database objects through the sp_rename system stored procedure. This procedure can rename tables, views, stored procedures, indexes, columns, and other user-created objects. However, some system objects and certain object types have restrictions on renaming.
-
(a) Use the bcp command
-
(b) Use the BULKINSERT statement
-
(c) Create a custom format file
-
(d) None of the above
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.
-
(a) Text
-
(b) Varbinary
-
(c) Varchar(max)
-
(d) Varchar
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.
-
(a) Create index
-
(b) Alter database
-
(c) Insert data
-
(d) Restore Database
C
Correct answer
Explanation
Among the operations listed, only Insert data (C) is allowed inside a trigger. Triggers execute in response to DML operations (INSERT, UPDATE, DELETE) and can themselves perform data modifications. CREATE INDEX, ALTER DATABASE, and RESTORE DATABASE are DDL operations that are not permitted within a trigger because triggers execute as part of the DML transaction and these DDL operations would break transactional integrity or require exclusive locks.