Explore key concepts and usage of SQLite PRAGMA commands with this quiz, designed to enhance your understanding of configuration, diagnostics, and database management query options. Ideal for users aiming to solidify foundational knowledge about SQLite PRAGMA statements, their effects, and common use cases.
Which PRAGMA command enables or disables enforcement of foreign key constraints in an SQLite database?
Explanation: PRAGMA foreign_keys is used to enable or disable the enforcement of foreign key constraints in an SQLite database. PRAGMA index_list is used to list indexes for a specific table, not to control foreign keys. PRAGMA page_size sets the size of the database page, and PRAGMA cache_size configures the number of pages held in memory cache. Only PRAGMA foreign_keys is relevant for this specific function.
What is the correct PRAGMA statement to retrieve the schema details of a table named 'users'?
Explanation: PRAGMA table_info('users') returns detailed information about the columns in the 'users' table, such as name, type, and whether the column is a primary key. PRAGMA table_schema and PRAGMA schema_info are not valid SQLite PRAGMAs. PRAGMA user_info('table') is an incorrect reference and does not exist in SQLite.
Which PRAGMA command is used to set or check the database's automatic vacuuming behavior?
Explanation: PRAGMA auto_vacuum allows users to read or set the database's auto-vacuum mode, which affects how deleted space is reclaimed. PRAGMA vacuum_settings and PRAGMA vacuum_mode are common misinterpretations but are not actual SQLite PRAGMAs. PRAGMA auto_vac is a typo and not recognized. Only PRAGMA auto_vacuum is valid.
To control whether SQLite uses memory or disk for temporary storage by default, which PRAGMA should be used?
Explanation: PRAGMA temp_store allows you to set if temporary storage is managed in memory or on disk. PRAGMA store_temp and PRAGMA temp_storage look similar but are not real PRAGMA commands in SQLite. PRAGMA memory_mode does not exist for controlling temp storage. Only PRAGMA temp_store is designed for this setting.
How can you obtain a list of all indexes associated with a table named 'orders' using a PRAGMA command?
Explanation: PRAGMA index_list('orders') gives you all indexes related to the 'orders' table. PRAGMA indexes and PRAGMA table_indexes are common misconceptions and invalid commands in SQLite. PRAGMA indexinfo is used to get detailed info about a specific index but does not list all indexes.
Which PRAGMA command is specifically designed to check for database corruption or integrity issues?
Explanation: PRAGMA integrity_check runs a thorough check to detect corruption or integrity errors in the database. PRAGMA check_integrity and PRAGMA database_check are misleading and do not exist in SQLite. PRAGMA file_integrity is not a valid SQLite command for this purpose.
If you want to configure the journal mode (e.g., DELETE, WAL) for an SQLite database, which PRAGMA should you use?
Explanation: PRAGMA journal_mode allows users to set or query the journal mode for a database, affecting how transactions are logged. PRAGMA mode_journal and PRAGMA journal_settings might look correct due to similar naming but are not valid SQLite PRAGMA commands. PRAGMA set_journal is also incorrect.
Which PRAGMA statement can disable or enable SQLite's automatic query planner functionality?
Explanation: PRAGMA automatic_index controls whether or not SQLite will automatically create temporary indexes to assist query planning. PRAGMA planner_mode and PRAGMA query_planner seem reasonable but are not real PRAGMAs. PRAGMA index_auto is a misnamed variant and not supported.
To check if Write-Ahead Logging (WAL) is active, which PRAGMA command can be used?
Explanation: PRAGMA journal_mode will show the current journal mode, such as WAL, so it's the right way to determine if Write-Ahead Logging is active. PRAGMA wal_status and PRAGMA write_ahead are not valid commands, while PRAGMA logging_mode is a plausible but incorrect option. Only PRAGMA journal_mode provides this information.
What PRAGMA statement returns the version of the SQLite library in use?
Explanation: PRAGMA library_version returns the version of the SQLite library itself. PRAGMA version and PRAGMA db_version are not valid PRAGMA commands. PRAGMA sqlite_version is a legitimate SQLite command but is used as a function, not as a PRAGMA, so PRAGMA library_version is the precise answer.