POSTGRESQL-ESSENTIALS practice question 15 of 15
Which psql meta-command displays the structure of a specific table including columns, types, and constraints?
Full set: 71 questionsThe psql meta-command \d tablename is used to describe a relation (table, view, index, sequence, or foreign table). When used with a table name, it provides a detailed description of the table's structure, listing all columns, their data types, collation, nullability, and default values. Crucially, it also displays associated indexes, constraints (such as primary keys, foreign keys, and check constraints), and triggers, which fully satisfies the requirements of the question. It is the direct equivalent of the describe command in other database clients.
B. \dt tablename: This command lists tables matching the specified pattern; it does not display the detailed structure (columns, constraints) of a specific table.
C. DESCRIBE tablename;: This is not a valid command in psql for describing table structure. DESCRIBE is used for prepared statements, and this syntax is common in other RDBMS like MySQL.
D. SHOW TABLE tablename;: This is invalid syntax. The SHOW command in PostgreSQL is used to display the value of a run-time parameter, not to describe a table.
1. PostgreSQL 16 Documentation, psql, Meta-Commands: The official documentation explicitly lists and describes the \d command. It states: "For tables...lists the columns, their types...and any special attributes...Associated indexes, constraints, rules, and triggers are also listed."
Source: PostgreSQL 16 Documentation, Chapter 35. psql, Section 35.5. Meta-Commands.
Link: https://www.postgresql.org/docs/16/app-psql.html#PSQL-META-COMMANDS-DESCRIBE
2. University of California, Berkeley, Courseware: In the "Connecting to PostgreSQL" guide for the Data 101 course, the \d command is introduced as the primary method for inspecting the schema of a table within psql.
Source: UC Berkeley, Data 101, "Lab 01: Introduction to Jupyter and Data 101," Section on psql.
Reference: Course materials frequently demonstrate \d to "describe a relation."
3. PostgreSQL Tutorial Website (Official Vendor Resource): The official tutorial demonstrates the use of psql commands. In the "Accessing A Database" section, it introduces \d as the command to "find out what tables the database contains and what their columns are."
Source: PostgreSQL Tutorial, Chapter 1. Getting Started, Section 1.3. Accessing a Database.
Link: https://www.postgresql.org/docs/current/tutorial-accessdb.html
Keep practicing
Take the free POSTGRESQL-ESSENTIALS practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other POSTGRESQL-ESSENTIALS practice questions
- Question 1What is the purpose of the autovacuum parameter in PostgreSQL?
- Question 2Which psql meta-command is used to display all roles and their attributes?
- Question 3SERIAL and IDENTITY columns can be used to add an auto-incrementing column in a Postgres …
- Question 4You are connected to a PostgreSQL database. After executing a complex query an error mess…
- Question 5Which PostgreSQL configuration parameter controls the amount of memory used for sorting o…
- Question 6You want to set the maximum time to complete client authentication to 10 seconds. Which p…
