Debug School

Akanksha
Akanksha

Posted on

Top 30 PostgreSQL Interview Questions with Answers

1. What is PostgreSQL?

A. An open-source relational database management system.
B. A NoSQL database.
C. A document database.
D. A key-value store.
Answer: A

2. Which SQL command is used to create a new database in PostgreSQL?

A. CREATE DATABASE
B. CREATE TABLE
C. CREATE SCHEMA
D. CREATE INDEX
Answer: A

3. What is the maximum number of columns a table can have in PostgreSQL?

A. 256
B. 1000
C. Unlimited
D. 1664
Answer: D

4. What does ACID stand for in the context of database management?

A. Atomicity, Consistency, Integrity, Durability
B. Association, Constraints, Integrity, Data
C. Aggregation, Consistency, Inheritance, Dependencies
D. Atomicity, Consistency, Isolation, Dependency
Answer: A

5. Which PostgreSQL data type is used to store binary data?

A. INT
B. CHAR
C. BYTEA
D. BLOB
Answer: C

6. Which command is used to start a PostgreSQL server?

A. pg_start
B. pg_server
C. pgsql
D. pg_ctl start
Answer: D

7. What is the default port number for PostgreSQL?

A. 5433
B. 3306
C. 5432
D. 1521
Answer: C

8. Which command is used to create a new user in PostgreSQL?

A. CREATE USER
B. ADD USER
C. INSERT USER
D. NEW USER
Answer: A

9. Which JOIN clause combines rows from two or more tables based on a related column between them?

A. CROSS JOIN
B. INNER JOIN
C. OUTER JOIN
D. SELF JOIN
Answer: B

10. Which statement is used to delete records from a table in PostgreSQL?

A. DELETE
B. TRUNCATE
C. REMOVE
D. DROP
Answer: A

11. Which of the following is not a valid data type in PostgreSQL?

A. JSON
B. XML
C. BOOLEAN
D. CHAR(n)
Answer: B

12. Which statement is used to change data in a PostgreSQL table?

A. UPDATE
B. ALTER
C. CHANGE
D. MODIFY
Answer: A

13. Which index type in PostgreSQL enforces uniqueness on a column or a set of columns?

A. B-tree
B. GIN
C. GiST
D. UNIQUE
Answer: D

14. What does a foreign key constraint do in PostgreSQL?

A. Enforces uniqueness in a column.
B. Ensures that data in a column is unique.
C. Establishes a link between two tables based on a key.
D. Requires a column to contain only integer values.
Answer: C

15. Which command is used to revoke privileges from a user in PostgreSQL?

A. REVOKE
B. DENY
C. REMOVE
D. WITHDRAW
Answer: A

16. Which of the following is an aggregate function in PostgreSQL?

A. LENGTH
B. COUNT
C. TRIM
D. CONCAT
Answer: B

17. What is the primary purpose of the VACUUM command in PostgreSQL?

A. To create a new table.
B. To clean up and optimize the database.
C. To add new rows to a table.
D. To modify table structure.
Answer: B

18. Which PostgreSQL extension is used to store and query JSON data efficiently?

A. jsonb
B. json
C. hstore
D. xml
Answer: A

19. What is the purpose of the COMMIT statement in PostgreSQL?

A. To save changes to the database permanently.
B. To cancel ongoing transactions.
C. To create a new table.
D. To roll back changes made in the current session.
Answer: A

20. What is a subquery in PostgreSQL?

A. A query that retrieves data from multiple tables.
B. A query that retrieves data from a single table.
C. A query that is embedded within another query.
D. A query that aggregates data.
Answer: C

21. Which SQL statement is used to add a new column to an existing table in PostgreSQL?

A. ALTER TABLE
B. ADD COLUMN
C. CREATE COLUMN
D. INSERT COLUMN
Answer: A

22. What does the term "PL/pgSQL" refer to in PostgreSQL?

A. A popular web framework for PostgreSQL.
B. A procedural language for writing functions and triggers in PostgreSQL.
C. A database management tool.
D. A high-availability clustering solution.
Answer: B

23. Which statement is used to sort the result set of a SELECT query in PostgreSQL?

A. ORDER BY
B. SORT BY
C. GROUP BY
D. HAVING
Answer: A

24. What is the purpose of the ANALYZE command in PostgreSQL?

A. To generate statistics for query optimization.
B. To create new indexes on tables.
C. To back up the database.
D. To check the integrity of the database.
Answer: A

25. Which operator is used to concatenate strings in PostgreSQL?

A. +
B. &
C. ||
D. CONCAT
Answer: C

26. Which statement is used to rename a table in PostgreSQL?

A. RENAME TABLE
B. ALTER TABLE
C. CHANGE TABLE
D. MODIFY TABLE
Answer: B

27. What is a schema in PostgreSQL?

A. A subset of a table's data.
B. A logical container for database objects.
C. A type of data structure in PostgreSQL.
D. A synonym for a database.
Answer: B

28. Which command is used to create an index on a table in PostgreSQL?

A. ADD INDEX
B. CREATE INDEX
C. INDEX TABLE
D. NEW INDEX
Answer: B

29.Which function is used to extract a substring from a string in PostgreSQL?

A. LEFT
B. RIGHT
C. SUBSTRING
D. EXTRACT
Answer: C

30. What is the purpose of the TRUNCATE statement in PostgreSQL?

A. To delete all records from a table.
B. To remove a column from a table.
C. To truncate a string.
D. To delete specific records from a table.
Answer: A

31. Which statement is used to drop a table in PostgreSQL?

A. DROP
B. DELETE
C. TRUNCATE
D. REMOVE
Answer: A

Top comments (0)