Scrivio Interview library

Oracle and SQL Server

24 questions in 7 subtopics.

Oracle sequences, ROWNUM and FETCH FIRST

ConceptFoundations7 min read
How do Oracle sequences work with JPA's @GeneratedValue(strategy = SEQUENCE) and allocationSize? What happens if the sequence INCREMENT BY does not match allocationSize?
DebuggingFoundations6 min read
A developer writes SELECT * FROM orders WHERE ROWNUM <= 10 ORDER BY created_at DESC in Oracle to get the 10 newest orders, and the results are wrong. Explain why and give two correct versions.
ScenarioIntermediate6 min read
An Oracle RAC system shows heavy 'enq: SQ - contention' and index block contention on the primary key of a hot orders table during peak inserts. How would you address it?
DesignAdvanced7 min read
Your company is migrating 60 Oracle schemas to PostgreSQL. Applications rely on Oracle sequences, ROWNUM pagination, and SYSDATE in SQL. How do you plan the SQL and id generation side of the migration?

Oracle undo and read consistency

ConceptFoundations6 min read
How does Oracle give a query a consistent view of data while other transactions update the same rows, without read locks?
DebuggingIntermediate7 min read
A long-running Java report on Oracle fails after 2 hours with ORA-01555: snapshot too old. What does it mean, and how do you fix it?
ScenarioAdvanced7 min read
You are moving a workload from Oracle to PostgreSQL. Both use MVCC, but differently. What operational differences in versioning should your teams expect?
LeadershipPrincipal7 min read
Oracle's flashback features (flashback query, flashback table, flashback database) have been used by your DBAs for years to recover from bad deploys. As you consider leaving Oracle, how do you assess what this capability is worth and what replaces it?

PL/SQL basics

CodingFoundations6 min read
Write a PL/SQL procedure that transfers an amount between two accounts and raises an error if the balance is too low, and show how you would call it from Java with JDBC.
ScenarioIntermediate7 min read
A Java service calls a PL/SQL function row by row in a loop for 500,000 records, and the job takes hours. What are the costs involved and how do you speed it up?
LeadershipAdvanced6 min read
A core system holds 400,000 lines of business logic in PL/SQL packages, and the company wants to move to Java services and possibly off Oracle. How do you plan this?

SQL Server snapshot isolation

ConceptFoundations6 min read
What is the difference between SQL Server's READ COMMITTED with locking, READ_COMMITTED_SNAPSHOT (RCSI), and SNAPSHOT isolation?
ScenarioIntermediate6 min read
A Java application on SQL Server suffers frequent deadlocks between a reporting SELECT and order updates. The DBA proposes enabling READ_COMMITTED_SNAPSHOT. What do you check before turning it on?
DesignAdvanced5 min read
Teams use NOLOCK hints widely in SQL Server queries to avoid blocking. What risks does that carry, and what platform-level policy would you set instead?

SQL Server clustered indexes

ConceptFoundations6 min read
What is a clustered index in SQL Server, how does it differ from a nonclustered index, and why does the choice of clustering key matter?
DebuggingIntermediate7 min read
A table clustered on a random UUID primary key (NEWID()) shows heavy page splits, fragmentation above 90 percent and slow inserts. What options do you have, including from a Java application?
ScenarioAdvanced7 min read
You are designing tables for a system that must run on both SQL Server and PostgreSQL. PostgreSQL tables are heaps, SQL Server tables are usually clustered. How does this difference affect schema and query design?

JDBC drivers and dialect differences

ConceptFoundations6 min read
Name the JDBC driver coordinates and typical URL formats for Oracle and SQL Server, and two behaviour differences a Java developer notices compared with PostgreSQL.
DebuggingIntermediate6 min read
A query on SQL Server filters on a VARCHAR(20) indexed column with a JDBC PreparedStatement parameter. It does an index scan instead of a seek and takes 2 seconds. The same query in SSMS with a literal is fast. Why?
DesignAdvanced6 min read
Your product must support PostgreSQL, Oracle and SQL Server for on-premise customers. How do you structure data access, migrations and testing so dialect differences do not cripple the team?
LeadershipPrincipal6 min read
Supporting three database engines has slowed your product for years. Sales says enterprise customers demand Oracle and SQL Server. How do you decide whether to drop support for one or more engines?

Licensing and cost considerations

ConceptIntermediate6 min read
What licensing factors drive the cost of Oracle Database and SQL Server deployments, and how do they affect architecture choices such as virtualisation and read replicas?
ScenarioAdvanced7 min read
An internal audit found that a team enabled an Oracle feature (Diagnostics Pack AWR reports and Partitioning) without licences. How do you respond and prevent recurrence?
LeadershipPrincipal7 min read
Your company spends 9 million dollars a year on commercial database licences. The CFO asks whether to move to PostgreSQL. How do you build the business case and the risk assessment?