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
-
AddUpdateChanges()
-
Save()
-
SaveChanges()
-
InsertUpdateChanges()
C
Correct answer
Explanation
The correct method name is SaveChanges(), which persists all pending changes to the database. This is the standard method on DbContext in Entity Framework. Options A and D are non-existent method names, while B (Save()) is incomplete - the actual method is SaveChanges().
-
Entity SQL
-
LINQ to Entities
-
LINQ to SQL
-
LINQ to Entity SQL
A
Correct answer
Explanation
Entity SQL is specifically designed for building and executing dynamic queries at runtime, as it's a string-based query language similar to traditional SQL. LINQ to Entities is compile-time bound and not suitable for truly dynamic queries. LINQ to SQL is a different technology for SQL Server specifically, not Entity Framework.
-
AcceptChanges
-
Update
-
GetChanges
-
Accept
A
Correct answer
Explanation
AcceptChanges is the specific method in DataSet/DataTable that commits all pending changes since the last AcceptChanges call. It updates the RowState of all rows to Unchanged. Update is a DataAdapter method for database synchronization, GetChanges returns pending changes, and Accept is not a valid method.
-
Add()
-
NewRow()
-
Read()
-
ExecuteReader()
B
Correct answer
Explanation
NewRow() creates a new DataRow object with the schema of the table but does NOT add it to the table's Rows collection - you must call DataTable.Rows.Add() afterward. Add() directly adds to the collection. Read() and ExecuteReader() are data retrieval methods.
-
Yes
-
No
-
Can't say
-
None of the above
B
Correct answer
Explanation
Hibernate does not allow mixing table-per-class hierarchy (union subclass) and table-per-subclass (joined subclass) inheritance strategies within the same inheritance hierarchy. You must choose one strategy per inheritance hierarchy. Mixing these strategies would create ambiguous mappings and is not supported by Hibernate.
-
By using the insert="false" and update="false" attributes
-
By using the isinsert="false" and isupdate="false" attributes.
-
By using the isinsert="no" and isupdate="no" attributes
-
None
A
Correct answer
Explanation
Setting insert="false" and update="false" in Hibernate mapping prevents the property from being included in INSERT and UPDATE statements. The property can still be read from the database but won't be modified during save operations. This is useful for database columns that are managed by triggers or are derived/calculated values.
-
Session.load();
-
Session.get();
-
Session.fetch();
-
None of the above
B
Correct answer
Explanation
In Hibernate, Session.get() immediately queries the database and returns null if the corresponding row does not exist, which is ideal when existence is uncertain. Conversely, Session.load() assumes the row exists, returns a proxy, and throws an exception later if the record is missing.
-
cursor CAPITALS is
-
select CITY, STATE
-
into my_city, my_state
-
from CITIES
-
where CAPITAL = 'Y';
-
There are no errors in these statements
C
Correct answer
Explanation
The INTO clause must appear AFTER the SELECT clause in PL/SQL cursor declarations. The correct order is: CURSOR name IS SELECT columns INTO variables FROM table WHERE condition. Here 'into my_city, my_state' appears before 'from CITIES', which is a syntax error.
-
Bag has index column
-
Bag permits duplicate element values
-
Bag does not permits duplicate element values
-
None
B
Correct answer
Explanation
In Hibernate, a Bag collection permits duplicate element values and does not maintain index information. Unlike List which requires an index column, Bag is like an unordered collection that allows duplicates. This makes it simpler but less powerful than List for ordering operations.
-
Delete * from table T1
-
Delete all from T1
-
Delete * from T1
-
Delete From T1
D
Correct answer
Explanation
To delete all rows from a table T1, use 'DELETE FROM T1'. Option A is incorrect because DELETE doesn't use '*'. Option B is incorrect because 'all' is not valid SQL syntax. Option C is incorrect for the same reason as A. The correct syntax is DELETE FROM table_name with no WHERE clause.
-
Sequence
-
Trigger
-
Schema
-
View
D
Correct answer
Explanation
In DB2, an Alias is an alternative name for a View. Aliases cannot be created for Sequences, Triggers, or Schemas. An Alias provides a way to reference a View with a different name, which can be useful for simplifying names or providing application-specific naming.
-
Drop
-
Alter
-
Delete
-
Rollback
C
Correct answer
Explanation
Triggers are fired by DML operations (INSERT, UPDATE, DELETE). Among the options, only Delete is a DML operation that can cause a trigger to fire. Drop and Alter are DDL operations and don't fire triggers. Rollback is a transaction control command, not a DML operation.
-
When it is created
-
When it is referenced in an INSERT statement
-
The first time any executable SQL statement references it
-
Any time an executable SQL statement references it
D
Correct answer
Explanation
A view is a virtual table that stores only a query definition, not data. Every time an executable SQL statement references the view, the underlying query executes to produce the result set dynamically - the view is repopulated on each reference.
-
View
-
Catalog Table
-
Stored Procedure
-
Global Temprory Table
A
Correct answer
Explanation
INSTEAD OF triggers can be created on views to intercept insert, update, or delete operations against the view and redirect them to the underlying base tables. Triggers cannot be created on catalog tables, stored procedures, or global temporary tables.