PostgreSQL Interview Questions and Answers
Ques 6. What is a subquery, and how is it different from a JOIN?
A subquery is a query nested within another query, returning a single value or a set of values. JOIN combines rows from two or more tables based on a related column.
Ques 7. How can you optimize a PostgreSQL query for better performance?
Optimization techniques include using indexes, proper query design, and analyzing query execution plans.
Ques 8. What is a stored procedure, and how can you create one in PostgreSQL?
A stored procedure is a set of SQL statements stored in the database and executed as a single unit. You can create one using the CREATE PROCEDURE statement.
Ques 9. Explain the purpose of the EXPLAIN command in PostgreSQL.
The EXPLAIN command shows the execution plan of a statement, helping to optimize queries by revealing how PostgreSQL processes them.
Ques 10. What is a foreign key, and how does it enforce referential integrity?
A foreign key is a field that refers to the primary key in another table. It enforces referential integrity by ensuring that values in the foreign key match values in the referenced table's primary key.
Most helpful rated by users:
- Explain the concept of ACID properties in the context of databases.
- What is the purpose of the WHERE clause in a PostgreSQL query?