SQLite Interview Questions and Answers
Intermediate / 1 to 5 years experienced level questions & answers
Ques 1. How to create an AUTOINCREMENT field?
For autoincrement, you have to declare a column of the table to be INTEGER PRIMARY KEY, then whenever you insert a NULL into that column of the table, the NULL is automatically converted into an integer which is one greater than the largest value of that column over all other rows in the table, or 1 if the table is empty.
Ques 2. Explain the difference between CHAR and VARCHAR in SQLite.
CHAR and VARCHAR are both text types, but CHAR always reserves space for the specified length, while VARCHAR only stores the actual data without padding.
Ques 3. What is the purpose of the INDEX in SQLite?
An INDEX in SQLite is used to improve the speed of data retrieval operations on a table.
Ques 4. How to update data in a SQLite table?
You can update data in a SQLite table using the UPDATE statement, like this: `UPDATE table SET column1 = value1 WHERE condition;`.
Ques 5. Explain the difference between PRIMARY KEY and UNIQUE constraints in SQLite.
A PRIMARY KEY constraint uniquely identifies each record in a table, and there can only be one PRIMARY KEY in a table. The UNIQUE constraint, on the other hand, ensures that all values in a column are unique.
Ques 6. What is the purpose of the FOREIGN KEY constraint in SQLite?
The FOREIGN KEY constraint is used to link two tables together by referencing the primary key of one table as a foreign key in another, enforcing referential integrity.
Ques 7. How to perform a JOIN operation in SQLite?
To perform a JOIN operation in SQLite, you can use the JOIN keyword in your SELECT statement, specifying the tables and the join condition.
Ques 8. What is the purpose of the GROUP BY clause in SQLite?
The GROUP BY clause in SQLite is used to group rows that have the same values in specified columns into summary rows, like those returned by aggregate functions.
Ques 9. Explain the difference between INNER JOIN and LEFT JOIN in SQLite.
INNER JOIN returns only the matching rows from both tables, while LEFT JOIN returns all rows from the left table and the matching rows from the right table, filling in with NULLs for non-matching rows.
Ques 10. Explain the purpose of the HAVING clause in SQLite.
The HAVING clause in SQLite is used to filter the results of a GROUP BY clause based on specified conditions, similar to the WHERE clause for individual rows.
Ques 11. What is a subquery in SQLite?
A subquery in SQLite is a query nested inside another query, typically used to retrieve data that will be used in the main query's condition or result.
Ques 12. Explain the purpose of the CASE statement in SQLite.
The CASE statement in SQLite is used to perform conditional logic within a SQL query, allowing you to return different values based on specified conditions.
Ques 13. What is the purpose of the ATTACH DATABASE statement in SQLite?
The ATTACH DATABASE statement in SQLite is used to attach another database file to the current database, allowing you to query tables from both databases.
Ques 14. Explain the use of the PRAGMA cache_size command in SQLite.
The PRAGMA cache_size command in SQLite is used to set or query the size of the page cache, affecting the amount of memory SQLite uses for caching database pages.
Ques 15. What is the purpose of the strftime function in SQLite?
The strftime function in SQLite is used to format date and time values according to a specified format string.
Ques 16. Explain the purpose of the PRAGMA page_size command in SQLite.
The PRAGMA page_size command in SQLite is used to set or query the size of the database page, affecting the storage efficiency and performance of the database.
Ques 17. How to create a trigger in SQLite?
You can create a trigger in SQLite using the CREATE TRIGGER statement, specifying the trigger name, timing (BEFORE or AFTER), event (INSERT, UPDATE, DELETE), and the SQL statements to execute.
Ques 18. Explain the purpose of the PRAGMA foreign_keys command in SQLite.
The PRAGMA foreign_keys command in SQLite is used to enable or disable the enforcement of foreign key constraints during a transaction.
Most helpful rated by users: