Welcome to the PostgreSQL Quiz for beginners! Whether you're testing your knowledge or looking to learn something new, this quiz has you covered. We will be covering the fundamental concepts of PostgreSQL through 40+ multiple-choice questions. Let's dive in!
1. What is PostgreSQL?
Answer:
Explanation:
PostgreSQL is an open-source RDBMS known for its extensibility and standards compliance.
2. Which of the following is a key feature of PostgreSQL?
Answer:
Explanation:
PostgreSQL offers extensive support for JSON, allowing for a mix of structured and semi-structured data storage.
3. Which command-line utility is used for interactive PostgreSQL operations?
Answer:
Explanation:
psql is the interactive terminal for working with PostgreSQL.
4. Which SQL command is used to create a new PostgreSQL database?
Answer:
Explanation:
The command CREATE DATABASE is used to create a new PostgreSQL database.
5. How do you add a comment in SQL in PostgreSQL?
Answer:
Explanation:
In PostgreSQL, the double dash -- is used to add a single-line comment.
6. Which data type in PostgreSQL can be used to store binary data?
Answer:
Explanation:
The BYTEA type is used to store binary data or "byte arrays".
7. Which command in PostgreSQL is used to list all the available databases?
Answer:
Explanation:
In the psql interface, the command \l lists all available databases.
8. Which keyword is used in PostgreSQL to define a primary key constraint?
Answer:
Explanation:
The PRIMARY KEY constraint uniquely identifies each record in a table.
9. Which of the following PostgreSQL functions can be used to obtain the current date and time?
Answer:
Explanation:
In PostgreSQL, CURRENT_TIMESTAMP returns the current date and time.
10. What is the maximum length of a table name in PostgreSQL?
Answer:
Explanation:
By default, PostgreSQL has a maximum identifier length of 64 characters.
11. Which PostgreSQL function returns the number of characters in a string?
Answer:
Explanation:
The LENGTH() function in PostgreSQL is used to get the number of characters in a string.
12. What does the SERIAL keyword in PostgreSQL do?
Answer:
Explanation:
SERIAL is used to define auto-incrementing integer columns in PostgreSQL.
13. In which language is PostgreSQL written?
Answer:
Explanation:
PostgreSQL is primarily written in the C programming language.
14. Which of the following is NOT a valid backup option for PostgreSQL?
Answer:
Explanation:
While pg_dump, pg_restore, and pg_basebackup are valid PostgreSQL backup tools, pg_backup is not.
15. Which command can be used to see the query plan for a statement without executing it?
Answer:
Explanation:
The EXPLAIN command in PostgreSQL displays the execution plan of a SQL statement without running it.
16. Which PostgreSQL feature allows for partitioning tables?
Answer:
Explanation:
Table inheritance in PostgreSQL can be used as a way to achieve table partitioning.
17. How do you retrieve the version of the PostgreSQL server you're connected to?
Answer:
Explanation:
The version() function returns the version of the PostgreSQL server.
18. Which command-line utility is used for administrative tasks like creating, deleting, and maintaining PostgreSQL databases?
Answer:
Explanation:
createdb and dropdb are command-line utilities for creating and deleting PostgreSQL databases, respectively.
19. Which datatype is used in PostgreSQL to store IPv4 and IPv6 addresses?
Answer:
Explanation:
The INET type in PostgreSQL is used to store both IPv4 and IPv6 addresses.
20. Which command can be used to list all the tables in the current PostgreSQL database?
Answer:
Explanation:
In the psql interface, the command \dt lists all the tables in the current database.
21. Which of the following is NOT a locking mechanism in PostgreSQL?
Answer:
Explanation:
PostgreSQL does not have a "Segment Locks" mechanism.
22. PostgreSQL is often referred to as an ORDBMS. What does the "OR" stand for?
Answer:
Explanation:
PostgreSQL is often termed as an Object-Relational Database Management System (ORDBMS) because it supports both relational and object-oriented database features.
23. How would you retrieve unique values from a column named "names" in a table called "users"?
Answer:
Explanation:
The DISTINCT keyword is used to retrieve unique values from a column in PostgreSQL.
24. Which function would you use to obtain the current user name in PostgreSQL?
Answer:
Explanation:
The CURRENT_USER keyword in PostgreSQL returns the name of the current user.
25. Which command will allow you to switch to a different database named 'testdb' in the psql interface?
Answer:
Explanation:
In the psql interface, the command \c followed by the database name allows you to switch to a different database.
26. What is the primary role of the WAL in PostgreSQL?
Answer:
Explanation:
In PostgreSQL, WAL stands for Write Ahead Logging. It's a method where changes are logged before they are applied to the database, ensuring data integrity and consistency.
27. Which of the following data types would be best for storing monetary values in PostgreSQL?
Answer:
Explanation:
The MONEY type is specifically designed for storing currency amounts in PostgreSQL. It handles currency symbols and formatting.
28. What is the purpose of the VACUUM command in PostgreSQL?
Answer:
Explanation:
The VACUUM command reclaims storage occupied by dead tuples, and optionally, optimizes the database file structures.
29. Which of these is a PostgreSQL tool for creating a physical backup?
Answer:
Explanation:
pg_basebackup is used for taking base backups of a running PostgreSQL database cluster.
30. How do you concatenate two columns in PostgreSQL?
Answer:
Explanation:
In PostgreSQL, you can concatenate columns using the || operator.
31. Which of these commands is used to remove a table from PostgreSQL?
Answer:
Explanation:
The DROP TABLE command is used to remove a table from PostgreSQL.
32. What does the CASCADE option do when used with the DROP TABLE command?
Answer:
Explanation:
When using CASCADE with DROP TABLE, it ensures that the table and any dependent objects (like views) are dropped.
33. What is the default port on which PostgreSQL listens?
Answer:
Explanation:
By default, PostgreSQL listens on port 5432.
34. Which command in psql will list all the databases?
Answer:
Explanation:
In the psql interface, the \list or \l command lists all the available databases.
35. How would you describe the structure of a table named "employees" using psql?
Answer:
Explanation:
In psql, you can use the \d command followed by the table name to describe its structure.
36. If you want to see the list of users and their roles in psql, which command would you use?
Answer:
Explanation:
The \du command in psql lists all roles (users are also roles) and their attributes.
37. Which psql command would you use to turn on the timing of commands?
Answer:
Explanation:
The \timing command in psql can be used to turn the timing of commands on or off.
38. How would you quit out of the psql interface?
Answer:
Explanation:
To quit psql, you simply enter the command \q.
39. Which command is used to display the history of executed SQL commands in psql?
Answer:
Explanation:
The \s command in psql displays the history of SQL commands that have been executed in the current session.
40. What does the psql command \e do?
Answer:
Explanation:
The \e command in psql opens the last SQL command in a text editor. This is useful for long queries that need editing.
Comments
Post a Comment
Leave Comment