Q1
True / FalsePostgreSQL tables can have primary keys, which uniquely identify each row in the table.
A primary key is a field in a table which uniquely identifies each row/record in that table. PostgreSQL supports primary keys, ensuring that no duplicate values exist and that each value is unique.
Q2
True / FalseIn PostgreSQL, the CHAR and VARCHAR data types are used to store numeric values.
The CHAR and VARCHAR data types are used to store character strings, not numeric values. Numeric values are stored using data types like INTEGER, NUMERIC, etc.
Q3
True / FalsePostgreSQL supports JSON data types for storing JSON-formatted data.
PostgreSQL supports JSON and JSONB data types, allowing you to store JSON-formatted data in tables and perform operations on it.
Q4
True / FalseYou can create an index on a PostgreSQL table to improve query performance.
Indexes in PostgreSQL can be created on tables to improve the speed of data retrieval operations. They allow the database to find rows more efficiently.
Q5
True / FalseIn PostgreSQL, the FOREIGN KEY constraint enforces a link between the data in two tables.
A FOREIGN KEY in PostgreSQL is a key used to link two tables together, ensuring that the value in the child table corresponds to an actual value in the parent table.
Q6
True / FalseIn PostgreSQL, you cannot alter the structure of an existing table to add or drop columns.
PostgreSQL allows you to modify the structure of existing tables using the ALTER TABLE command to add, drop, or modify columns.
Q7
True / FalsePostgreSQL supports partitioned tables, which allow you to divide large tables into smaller, more manageable pieces.
Partitioning in PostgreSQL allows a table to be divided into smaller pieces, improving manageability and potentially query performance, especially for large datasets.
Q8
True / FalseIn PostgreSQL, CTID can be used to uniquely identify rows in a table for the duration of a transaction.
CTID is a system column in PostgreSQL that uniquely identifies a row within its table during a specific transaction. However, it can change after a VACUUM operation or if the row is updated.
Q9
True / FalsePostgreSQL does not support inheritance in tables, where a child table can inherit columns from a parent table.
PostgreSQL supports table inheritance, allowing a child table to inherit columns and constraints from a parent table, providing a way to model hierarchical data.
Q10
True / FalseIn PostgreSQL, the SERIAL data type can be used to automatically generate unique identifiers for table columns.
The SERIAL data type in PostgreSQL is used to create unique identifiers by automatically generating a sequence of numbers, often used for primary keys.
Q21
Multiple ChoiceWhich of the following SQL queries correctly creates a table with a primary key in PostgreSQL?
SQL Code
CREATE TABLE employees (
employee_id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
position VARCHAR(50) NOT NULL,
salary NUMERIC(10, 2) NOT NULL
);
This query creates an 'employees' table with 'employee_id' as the primary key, which is essential for uniquely identifying each row in the table.
Q26
Multiple ChoiceChoose the correct SQL command to create a table with a foreign key constraint in PostgreSQL.
SQL Code
CREATE TABLE orders (
order_id SERIAL PRIMARY KEY,
customer_id INT REFERENCES customers(customer_id),
order_date DATE NOT NULL
);
This query creates an 'orders' table where 'customer_id' is a foreign key referencing the 'customer_id' column in the 'customers' table, establishing a relationship between the tables.
Q28
Multiple ChoiceWhich SQL query correctly inserts data into a table, including a value for an auto-incrementing column in PostgreSQL?
SQL Code
INSERT INTO employees (name, position, salary)
VALUES ('John Doe', 'Manager', 75000.00)
RETURNING employee_id;
This query inserts a new row into the 'employees' table and returns the 'employee_id' of the newly inserted record, which is auto-incremented.
Q30
Multiple ChoiceWhich SQL query correctly creates a table with a composite primary key in PostgreSQL?
SQL Code
CREATE TABLE order_items (
order_id INT,
product_id INT,
quantity INT NOT NULL,
PRIMARY KEY (order_id, product_id)
);
This query creates an 'order_items' table where the combination of 'order_id' and 'product_id' serves as the composite primary key, ensuring that each pair is unique.