Q1
True / FalseThe DEFAULT constraint in PostgreSQL is used to provide a default value for a column if no value is specified.
In PostgreSQL, the DEFAULT constraint automatically assigns a default value to a column if no value is provided during the insert.
Q2
True / FalseIn PostgreSQL, a column with a DEFAULT constraint must always have a value specified during the insertion of a new row.
The purpose of the DEFAULT constraint is to provide a default value when no value is specified, so it's not necessary to provide a value explicitly during insertion.
Q3
True / FalseYou can add a DEFAULT constraint to an existing column in a PostgreSQL table.
PostgreSQL allows you to add a DEFAULT constraint to an existing column using the ALTER TABLE statement.
Q4
True / FalseIn PostgreSQL, the DEFAULT constraint can reference other columns in the same table.
A DEFAULT constraint cannot reference other columns or tables; it must be a constant expression.
Q5
True / FalseChanging the default value of a column in PostgreSQL using the DEFAULT constraint will automatically update the existing rows with the new default value.
Changing the default value only affects rows inserted after the change. Existing rows will retain their original values unless explicitly updated.
Q6
True / FalseIn PostgreSQL, the DEFAULT constraint can be used with all data types.
PostgreSQL supports DEFAULT constraints for all data types, including integers, text, date, and more.
Q7
True / FalseYou can set a DEFAULT constraint to use a PostgreSQL function, such as NOW() for a timestamp column.
PostgreSQL allows the use of functions as default values. For example, NOW() can be used to set the current timestamp as the default value for a column.
Q8
True / FalseIn PostgreSQL, removing a DEFAULT constraint from a column will remove all the existing default values from that column.
Removing a DEFAULT constraint does not affect existing rows; it only prevents new rows from using the default value.
Q9
True / FalseIn PostgreSQL, the DEFAULT constraint can include arithmetic expressions, such as setting the default value of a column to 100 + 50.
PostgreSQL supports arithmetic expressions in DEFAULT constraints, allowing calculations to be used as default values.
Q10
True / FalseWhen a DEFAULT constraint is specified for a column in PostgreSQL, it ensures that all values inserted into the column adhere to the specified default value.
The DEFAULT constraint only provides a default value if no value is specified during insertion. It does not enforce that all inserted values must be the default; explicit values can still be inserted.
Q12
Single ChoiceWhich of the following SQL statements correctly uses the DEFAULT constraint when creating a table?
The correct syntax for using the DEFAULT constraint in a CREATE TABLE statement is to place the DEFAULT keyword followed by the value after the column's data type.
Q23
Multiple ChoiceWhich SQL command creates a table with a DEFAULT constraint that uses an expression in PostgreSQL?
SQL Code
CREATE TABLE accounts (
account_id SERIAL PRIMARY KEY,
balance NUMERIC(12, 2) DEFAULT 1000 * 0.05
);
This command creates an 'accounts' table where the 'balance' column has a DEFAULT constraint that uses an expression (1000 * 0.05). The default value will be 50.00 if no value is provided.
Q25
Multiple ChoiceWhich SQL command creates a table with multiple columns having DEFAULT constraints in PostgreSQL?
SQL Code
CREATE TABLE products (
product_id SERIAL PRIMARY KEY,
price NUMERIC(10, 2) DEFAULT 9.99,
stock INT DEFAULT 0
);
This command creates a 'products' table with both 'price' and 'stock' columns having DEFAULT constraints. The 'price' column defaults to 9.99 and the 'stock' column defaults to 0.