How do you restore a database from a backup?
Short answer: SQL Server: To restore a full backup in SQL Server: - Full Restore RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backups\MyDatabase.bak'; - Transaction Log Restore RESTORE LOG MyDatabase FROM DISK = 'C:\Backups\MyDatabase_log.trn'; To restore a database to a specific point in time (using point-in-time recovery), you would restore the full backup and apply transaction logs.
Explain a bit more
RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backups\MyDatabase.bak'; RESTORE LOG MyDatabase FROM DISK = 'C:\Backups\MyDatabase_log.trn' WITH STOPAT = '2023-09-14T15:30:00'; -- Restore to a specific time PostgreSQL: To restore a backup from a pg_dump: - Full Restore from SQL dump psql -U username -d mydatabase < /path/to/backup/mydatabase.sql For binary dump (pg_dump -Fc): pg_restore -U username -d mydatabase /path/to/backup/mydatabase.dump MySQL: To restore a MySQL database: - Full Restore from SQL dump mysql -u username -p mydatabase < /path/to/backup/mydatabase.sql For restoring binary logs: mysqlbinlog /path/to/binlog/mysql-bin.000001 | mysql -u username -p
Real-world example (ShopNest)
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png