Q1
True / FalseIn PostgreSQL, the CREATE TABLE command is used to create a new table in the current database.
The CREATE TABLE command in PostgreSQL is used to create a new table in the current database.
Q2
True / FalsePostgreSQL does not allow specifying a default value for a column when creating a table.
PostgreSQL allows specifying a default value for a column using the DEFAULT keyword when creating a table.
Q3
True / FalseThe SERIAL keyword in PostgreSQL is used to create an auto-incrementing integer column.
In PostgreSQL, the SERIAL keyword is used to create an auto-incrementing integer column.
Q4
True / FalseIn PostgreSQL, you cannot create a table without specifying a primary key.
While it is a good practice to have a primary key, PostgreSQL does not require specifying a primary key when creating a table.
Q5
True / FalsePostgreSQL allows the use of foreign key constraints when creating a table.
PostgreSQL supports foreign key constraints to enforce referential integrity between tables.
Q6
True / FalseThe CREATE TABLE command in PostgreSQL does not support the CHECK constraint.
PostgreSQL supports the CHECK constraint, which allows specifying a condition that must be met for each row in the table.
Q7
True / FalseIn PostgreSQL, the INHERITS keyword allows a table to inherit columns from one or more parent tables
The INHERITS keyword in PostgreSQL allows a table to inherit columns and constraints from one or more parent tables.
Q8
True / FalsePostgreSQL supports partitioning tables using the PARTITION BY clause in the CREATE TABLE statement.
PostgreSQL supports table partitioning using the PARTITION BY clause, which allows dividing a large table into smaller, more manageable pieces.
Q9
True / FalseThe CREATE TABLE AS command in PostgreSQL creates a new table and populates it with the result of a query.
The CREATE TABLE AS command in PostgreSQL creates a new table based on the result of a query and populates it with the query result.
Q10
True / FalseIn PostgreSQL, you can use the CREATE TABLE command to create a table with an index on a column by specifying the index directly within the CREATE TABLE statement.
In PostgreSQL, you cannot specify an index directly within the CREATE TABLE statement. Instead, you need to create the index separately using the CREATE INDEX statement after the table has been created.
Q18
Single ChoiceWhich of the following CREATE TABLE statements defines a composite primary key?
Option B correctly defines a composite primary key, which includes both order_id and product_id as part of the primary key.
Q21
Multiple ChoiceWhich SQL command correctly creates a basic table in PostgreSQL with a primary key?
SQL Code
CREATE TABLE employees (
employee_id SERIAL PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
hire_date DATE NOT NULL
);
This command creates an 'employees' table with a primary key on 'employee_id' and includes several columns with specific data types.
Q22
Multiple ChoiceWhich SQL command is used 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 command creates an 'orders' table where the 'customer_id' is a foreign key that references the 'customer_id' column in the 'customers' table.
Q23
Multiple ChoiceWhich SQL command 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 command creates an 'order_items' table with a composite primary key composed of 'order_id' and 'product_id'.
Q24
Multiple ChoiceWhich SQL command correctly creates a table with a UNIQUE constraint on one of its columns?
SQL Code
CREATE TABLE users (
user_id SERIAL PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
password VARCHAR(100) NOT NULL
);
This command creates a 'users' table where the 'username' column must have unique values.
Q25
Multiple ChoiceWhich SQL command creates a table in PostgreSQL with a CHECK constraint to ensure a column's value is within a specific range?
SQL Code
CREATE TABLE products (
product_id SERIAL PRIMARY KEY,
product_name VARCHAR(100) NOT NULL,
price NUMERIC(10, 2) CHECK (price > 0 AND price < 10000)
);
This command creates a 'products' table with a CHECK constraint to ensure that the 'price' column's value is greater than 0 and less than 10,000.
Q26
Multiple ChoiceWhich SQL command creates a table with a column that has a default value in PostgreSQL?
SQL Code
CREATE TABLE accounts (
account_id SERIAL PRIMARY KEY,
username VARCHAR(50) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
This command creates an 'accounts' table where the 'created_at' column automatically uses the current timestamp if no other value is provided.
Q27
Multiple ChoiceWhich SQL command is used to create a table that automatically deletes rows older than a certain age in PostgreSQL?
SQL Code
CREATE TABLE session_logs (
session_id SERIAL PRIMARY KEY,
user_id INT NOT NULL,
login_time TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT chk_login_time CHECK (login_time > CURRENT_TIMESTAMP - INTERVAL '1 year')
);
This command creates a 'session_logs' table with a CHECK constraint ensuring that 'login_time' is within the last year, effectively limiting row age.
Q28
Multiple ChoiceWhich SQL command creates a partitioned table in PostgreSQL by range?
SQL Code
CREATE TABLE sales (
sale_id SERIAL PRIMARY KEY,
sale_date DATE NOT NULL,
amount NUMERIC(10, 2) NOT NULL
) PARTITION BY RANGE (sale_date);
This command creates a 'sales' table partitioned by range based on the 'sale_date' column, which allows for more efficient querying and management of time-based data.
Q29
Multiple ChoiceWhich SQL command is used to create a table with a JSONB column in PostgreSQL?
SQL Code
CREATE TABLE events (
event_id SERIAL PRIMARY KEY,
event_data JSONB NOT NULL,
event_time TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
This command creates an 'events' table where 'event_data' is stored as JSONB, allowing for efficient storage and querying of JSON data.
Q30
Multiple ChoiceWhich SQL command creates a table with a generated column in PostgreSQL?
SQL Code
CREATE TABLE invoices (
invoice_id SERIAL PRIMARY KEY,
amount NUMERIC(10, 2) NOT NULL,
tax NUMERIC(10, 2) GENERATED ALWAYS AS (amount * 0.15) STORED
);
This command creates an 'invoices' table where the 'tax' column is a generated column that calculates 15% of the 'amount' automatically.