Delve into key concepts of SQLite backup, restore, and data export with this quiz designed to reinforce best practices and technical knowledge. Enhance your understanding of core commands, formats, and procedures to manage database safety and migration efficiently.
Which SQLite command creates a complete backup of a database and writes it to a file called backup.db?
Explanation: The .backup command in SQLite copies the entire database to a specified file like backup.db. The .restore command is used to load a backup, not create one. .export is not a valid SQLite command, and .copy is used for copying tables, not making full backups.
What is the correct command to export contents of a table named 'users' to a CSV file in SQLite?
Explanation: Setting the mode to CSV and using .output with SELECT exports the data into a CSV file. .export is not a valid command, .backup is for full database backup, and .save only saves the main database, not in CSV format.
Given a backup file named 'mybackup.db', which command will restore this into the current SQLite session?
Explanation: The .restore command loads the contents of a backup into the current database. .import is for importing data (such as CSV), .recover is used for recovering from a corrupted database, and .load is meant for loading extensions, not backups.
If you need to move data between SQLite and a spreadsheet program, which format is most commonly used for data export?
Explanation: CSV is a widely accepted data format for spreadsheet programs, making it ideal for data export to such applications. SQL is a notation for commands, JSON is less commonly supported in spreadsheet programs, and DB refers to binary database files.
Why is it important to ensure no active write operations during an SQLite backup?
Explanation: Active write operations can result in a backup that is inconsistent or corrupted. Reducing backup size or increasing export speed are not direct reasons related to active writes. File format cannot be changed by simply halting write operations.
When importing a CSV file named 'data.csv' into an existing table 'records', what should be done first in SQLite?
Explanation: .mode csv sets the input format for the import in SQLite to recognize CSV files correctly. .backup creates backups and isn’t for imports, .compress isn’t a valid command, and .encode csv is not recognized by SQLite for this purpose.
What does the SQLite .dump command produce when run in the command-line tool?
Explanation: .dump outputs SQL statements that can be used to reconstruct the entire database schema and insert its data. It does not create a binary backup, doesn’t encrypt the database, and is not meant to produce CSV exports.
If you want to export only active users from an 'accounts' table to CSV, how would you filter the data?
Explanation: By adding a WHERE clause to SELECT, only rows meeting the criteria are exported. There is no .limit command, and changing file extensions does not filter data. Deleting data manually from the file is inefficient and error-prone.
Which SQLite feature allows creating a backup copy even while the application is connected and in use?
Explanation: The online backup API enables safe backups during active connections. Offline export would require disconnection, session closure ends the connection entirely, and vacuum is used for database maintenance, not backup.
If a CSV export from SQLite contains only column headers but no data, what is a likely cause?
Explanation: An empty CSV with only headers usually means the query retrieved no data. An incorrect output path or encryption would result in errors or unusable files. Write-locked tables prevent changes but don’t affect SELECT, and hence don’t cause empty exports.