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
-
Current_date
-
Datachange
-
Gettime
-
Convert
C
Correct answer
Explanation
CURRENT_DATE is a valid Sybase date function. DATACHANGE (or DATECHANGE) exists in Sybase for tracking data modifications. CONVERT is a standard Sybase function for data type conversion. GETTIME() is not a standard Sybase function - the correct function is GETDATE() which returns both date and time. Sybase does not have a GETTIME() function.
-
Their name must begin with @
-
They are local to the batch or stored procedure where they are declared
-
They can be declared in a select statement
-
They cannot have a datatype of text or image
C
Correct answer
Explanation
Local variables in Sybase must begin with the @ symbol (option A is true). They are local to the batch or stored procedure where declared (option B is true). They cannot have text or image datatypes (option D is true). Option C is NOT true - variables cannot be declared in a SELECT statement. They must be declared using the DECLARE statement before being used in SELECT or other statements.
A
Correct answer
Explanation
In older versions of Sybase, the maximum number of indexes per user table was 250 (one clustered index plus 249 non-clustered indexes). This limit was increased in later versions. Option B (255) is close but not the standard limit for these older versions. The other values (2065, 1026) are not standard Sybase index limits. This is version-specific knowledge.
B
Correct answer
Explanation
You can add constraints to existing tables using ALTER TABLE, but you add constraints to existing columns, not by creating new columns. The statement claims constraints are added 'by creating new column' which is not correct - constraints are added to columns that already exist. You can also add new columns WITH constraints, but the constraint itself is not created by adding a column. The statement is false.
-
Strong Question Language
-
Structured Query Language
-
Structured Question Language
-
None of the Above
B
Correct answer
Explanation
SQL stands for Structured Query Language, the standard language for relational database operations like querying, updating, and managing data in RDBMS systems.
-
ASCENDING
-
DESCENDING
-
RANDOM
-
PHYSICAL
A
Correct answer
Explanation
SQL ORDER BY defaults to ASCENDING order if no direction is specified. This applies to all data types - numbers sort smallest to largest, text A to Z, dates earliest to latest.
-
UNION only selects distinct values, UNION ALL selects all values (excluding ?duplicates)?
-
UNION ALL only selects distinct values, UNION selects all values (including ?duplicates)?
-
UNION only selects distinct values, UNION ALL selects all values (including ?duplicates)?
-
UNION ALL only selects distinct values, UNION selects all values (excluding ?duplicates)?
C
Correct answer
Explanation
UNION removes duplicate rows from the combined result set, while UNION ALL keeps all rows including duplicates. UNION ALL is faster because it skips the duplicate elimination step.
B
Correct answer
Explanation
For a non-correlated subquery (the standard case implied by the wording), the subquery executes once and returns its result set to be used by the main query. The main query then filters its 10 records using the 5 records from the subquery. Only a correlated subquery would execute once per main query row (10 times), but the question does not specify correlation.
-
WHERE
-
HAVING
-
HAVING BY
-
ORDER BY
B
Correct answer
Explanation
The HAVING clause is specifically designed to filter groups after the GROUP BY operation has aggregated the data. The WHERE clause filters individual rows before grouping, which is why it cannot be used with aggregate functions. HAVING BY and ORDER BY are not filtering clauses for grouped data.
-
Delete
-
Truncate
-
Insert
-
Update
B
Correct answer
Explanation
TRUNCATE is a DDL (Data Definition Language) operation that bypasses the transaction log and does not fire triggers. DELETE, INSERT, and UPDATE are DML (Data Manipulation Language) operations that respect triggers. This is why TRUNCATE is faster but also riskier - you cannot roll it back or trigger cleanup logic.
-
Increase the performance during SELECT operation
-
Degrade the performance during INSERT operation?
-
Degrade the performance during the UPDATE or DELETE operation
-
All of the above
D
Correct answer
Explanation
While multiple indexes can speed up SELECT queries by avoiding full table scans, every index must be updated during INSERT, UPDATE, and DELETE operations. Consequently, having numerous indexes improves read performance at the expense of write and modification performance.
-
Natural Key
-
Domain Key
-
Candidate Key
-
All of the Above
D
Correct answer
Explanation
Candidate keys and natural keys uniquely identify a row, establishing a logical relationship to its attributes. Since both are types of keys with this property, 'All of the Above' is the intended correct option.
A
Correct answer
Explanation
This is valid PL/SQL syntax for a simple SELECT statement. The BEGIN/END block creates an anonymous PL/SQL block, and the SELECT statement with IN clause is syntactically correct.
-
EXISTS(n)
-
EXTEND(n)
-
LIMIT(n)
-
SIZE(n)
B
Correct answer
Explanation
In Oracle PL/SQL, the EXTEND(n) method adds n elements to the end of a collection (varray or nested table). EXISTS(n) checks if an element exists at position n, LIMIT returns the maximum size of varrays, and SIZE returns the current number of elements. Only EXTEND actually increases collection size.