PostgreSQL Database Quiz Questions

Course Name:PostgreSQL
Chapter Name:Chapter 5 - DDL (Data Definition Language)
Lesson Content Link:ALTER TABLE
Current Quiz Count:30
Progress
0%
Q1
True / False

The ALTER TABLE command in PostgreSQL can be used to rename a table.

Q2
True / False

Using ALTER TABLE in PostgreSQL, you can add a new column to an existing table.

Q3
True / False

You cannot drop a column from a table using the ALTER TABLE command in PostgreSQL.

Q4
True / False

In PostgreSQL, the ALTER TABLE command can be used to change the data type of an existing column.

Q5
True / False

You can use ALTER TABLE to set a default value for an existing column in PostgreSQL.

Q6
True / False

The ALTER TABLE command in PostgreSQL can be used to rename a column in a table.

Q7
True / False

In PostgreSQL, ALTER TABLE cannot be used to add constraints to a table.

Q8
True / False

PostgreSQL allows the use of ALTER TABLE to partition a table.

Q9
True / False

Using the ALTER TABLE command to drop a column in PostgreSQL will automatically drop any indexes and constraints associated with that column.

Q10
True / False

In PostgreSQL, you can use the ALTER TABLE command to change the owner of a table.

Q11
Single Choice

Which of the following SQL statements is used to add a new column named email to an existing users table?

Q12
Single Choice

How can you change the data type of a column named birthdate in a table called customers from DATE to DATETIME?

Q13
Single Choice

Which command is used to remove a column named phone_number from an existing table named contacts?

Q14
Single Choice

You need to rename an existing column username to user_name in the accounts table. Which statement would you use?

Q15
Single Choice

How would you modify the salary column of the employees table to not allow NULL values?

Q16
Single Choice

If you want to drop a primary key from a table named orders, which SQL command would you use?

Q17
Single Choice

Consider a table products with a column price. How can you change the price column to allow NULL values and set the default value to 0?

Q18
Single Choice

Which command will you use to change the order of columns in the customers table, moving last_name to appear after first_name?

Q19
Single Choice

How do you add a foreign key constraint fk_order_customer to the orders table that references the id column of the customers table?

Q20
Single Choice

You have a table named employees with an existing unique index on the email column. How can you drop the unique index and then rename the email column to email_address in a single operation?

Q21
Multiple Choice

Which SQL command is used to add a new column to an existing table in PostgreSQL?

SQL Code
ALTER TABLE employees
ADD COLUMN department VARCHAR(50) NOT NULL;
Q22
Multiple Choice

Which SQL command correctly drops a column from a table in PostgreSQL?

SQL Code
ALTER TABLE orders
DROP COLUMN shipping_date;
Q23
Multiple Choice

Which SQL command is used to rename an existing column in a PostgreSQL table?

SQL Code
ALTER TABLE customers
RENAME COLUMN address TO location;
Q24
Multiple Choice

Which SQL command adds a UNIQUE constraint to an existing column in PostgreSQL?

SQL Code
ALTER TABLE users
ADD CONSTRAINT unique_email UNIQUE (email);
Q25
Multiple Choice

Which SQL command is used to modify a column's data type in an existing PostgreSQL table?

SQL Code
ALTER TABLE orders
ALTER COLUMN total_price TYPE NUMERIC(12, 2);
Q26
Multiple Choice

Which SQL command is used to set a default value for an existing column in a PostgreSQL table?

SQL Code
ALTER TABLE employees
ALTER COLUMN status SET DEFAULT 'active';
Q27
Multiple Choice

Which SQL command correctly drops a constraint from a PostgreSQL table?

SQL Code
ALTER TABLE products
DROP CONSTRAINT chk_price;
Q28
Multiple Choice

Which SQL command is used to rename an existing table in PostgreSQL?

SQL Code
ALTER TABLE orders
RENAME TO sales_orders;
Q29
Multiple Choice

Which SQL command adds a CHECK constraint to an existing table in PostgreSQL?

SQL Code
ALTER TABLE accounts
ADD CONSTRAINT chk_balance CHECK (balance >= 0);
Q30
Multiple Choice

Which SQL command in PostgreSQL is used to drop a foreign key constraint from a table?

SQL Code
ALTER TABLE orders
DROP CONSTRAINT fk_customer;