Q1
True / FalseIn PostgreSQL, a column defined as NOT NULL cannot store NULL values.
A NOT NULL constraint ensures that a column cannot have a NULL value. Any attempt to insert a NULL value into this column will result in an error.
Q2
True / FalseThe default setting for a column in PostgreSQL is NOT NULL.
By default, columns in PostgreSQL are allowed to store NULL values unless explicitly defined as NOT NULL.
Q3
True / FalseIn PostgreSQL, a column with a NOT NULL constraint can be altered to allow NULL values.
You can alter a column to remove the NOT NULL constraint using the ALTER TABLE statement, allowing it to store NULL values.
Q4
True / FalseYou can use the IS NULL condition in a PostgreSQL SELECT statement to filter rows with NULL values in a specific column.
The IS NULL condition is used to filter records with NULL values in a specified column.
Q5
True / FalseIn PostgreSQL, the COALESCE function can be used to return the first non-NULL value from a list of arguments.
The COALESCE function is used to return the first non-NULL value from its list of arguments.
Q6
True / FalseIn PostgreSQL, you cannot add a NOT NULL constraint to an existing column that contains NULL values
PostgreSQL will not allow you to add a NOT NULL constraint to a column that already contains NULL values. You must first update or remove those NULL values.
Q7
True / FalsePostgreSQL treats empty strings as NULL values.
PostgreSQL distinguishes between NULL values and empty strings. An empty string is a valid value, while NULL represents the absence of a value.
Q8
True / FalseYou can create a PostgreSQL table with a column that has both NULL and NOT NULL constraints.
A column cannot have both NULL and NOT NULL constraints simultaneously. It must be either NULL or NOT NULL.
Q9
True / FalseIn PostgreSQL, using the DISTINCT keyword will ignore NULL values in the result set.
The DISTINCT keyword does not ignore NULL values. It treats NULL as a unique value, so all NULL values are grouped together as one.
Q10
True / False: In PostgreSQL, when a NOT NULL constraint is added to an existing column using ALTER TABLE, the database performs a check to ensure there are no NULL values in that column before applying the constraint.
When adding a NOT NULL constraint to an existing column, PostgreSQL checks the column for any NULL values. If any are found, the operation fails until all NULL values are removed.
Q21
Multiple ChoiceWhich SQL command creates a table with a column that allows NULL values in PostgreSQL?
SQL Code
CREATE TABLE employees (
employee_id SERIAL PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50) NULL
);
This command creates an 'employees' table where the 'last_name' column is explicitly allowed to contain NULL values.
Q25
Multiple ChoiceWhich SQL command creates a table with both NULL and NOT NULL columns in PostgreSQL?
SQL Code
CREATE TABLE inventory (
item_id SERIAL PRIMARY KEY,
item_name VARCHAR(100) NOT NULL,
item_description TEXT,
quantity INT NOT NULL
);
This command creates an 'inventory' table where 'item_name' and 'quantity' columns are NOT NULL, while 'item_description' can be NULL.
Q26
Multiple ChoiceWhich SQL command creates a table with a default value that is NOT NULL in PostgreSQL?
SQL Code
CREATE TABLE users (
user_id SERIAL PRIMARY KEY,
username VARCHAR(50) NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'active'
);
This command creates a 'users' table where the 'status' column is NOT NULL and has a default value of 'active', ensuring that every row will have a value for this column.
Q29
Multiple ChoiceWhich SQL command defines a column as NOT NULL but provides a default value in PostgreSQL?
SQL Code
CREATE TABLE accounts (
account_id SERIAL PRIMARY KEY,
balance NUMERIC(10, 2) NOT NULL DEFAULT 0.00
);
This command creates an 'accounts' table where the 'balance' column is NOT NULL and provides a default value of 0.00, ensuring every record has a balance.
Q30
Multiple ChoiceWhich SQL command creates a table with a combination of NULL, NOT NULL, and DEFAULT constraints in PostgreSQL?
SQL Code
CREATE TABLE employees (
employee_id SERIAL PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50),
hire_date DATE NOT NULL DEFAULT CURRENT_DATE
);
This command creates an 'employees' table with a mix of NULL, NOT NULL, and DEFAULT constraints, ensuring that some columns must have values while others can be NULL.