All jobs / Database administrator / Automation
Database administrator interview question · 1–3 years
What do you put into a SQL script before it is allowed to run against production?
The strongest answer
An explicit transaction, a check that this is the right server and database, the affected row count shown before the commit, batching for anything large, and a tested way back
Why it works
Exactly — the environment check and the tested way back are the two people skip, and a second reviewer catches what you have stopped seeing.
What a good answer covers
- Wrap it in a transaction.
- Prove which server you are on.
- Show the row count first.
- Have a tested way back.
Answers that fall short
- Close, but not the strongest: I wrap it in a transaction and check the row count before I commit
Good; the missing piece is proving which server you are on, which is how scripts end up in the wrong environment. - Weak: I test it on staging first, and if it behaves there it is fine on production
Staging rarely has production’s data volume or its concurrent load, and both change what the script does. - Red flag: I run it, and if the count looks wrong I cancel the session quickly
Cancelling a running statement still rolls back, slowly, and only after it has blocked everything else for a while.
Who gets asked this
More Automation questions
- The nightly maintenance job has not run for three weeks. Nobody noticed, because the dashboard only shows…
- What does it take to make a maintenance script safe to run twice, and why insist on it?
- How do your maintenance and backup jobs authenticate to the databases, without a password sitting in a script?
- Two hundred database servers need the same configuration change, and you are writing a PowerShell script to…
- You inherit a fleet where each DBA keeps their own scripts on their own jump box, and the checks differ from…
- You are writing a small shell script that takes a backup on a Linux database server. What must it do besides…