PostgreSQL Database Quiz Questions

Course Name:PostgreSQL
Chapter Name:Chapter 3 - Database Tables, Columns and Rows
Lesson Content Link:Database Table
Current Quiz Count:30
Progress
0%
Q1
True / False

PostgreSQL tables can have primary keys, which uniquely identify each row in the table.

Q2
True / False

In PostgreSQL, the CHAR and VARCHAR data types are used to store numeric values.

Q3
True / False

PostgreSQL supports JSON data types for storing JSON-formatted data.

Q4
True / False

You can create an index on a PostgreSQL table to improve query performance.

Q5
True / False

In PostgreSQL, the FOREIGN KEY constraint enforces a link between the data in two tables.

Q6
True / False

In PostgreSQL, you cannot alter the structure of an existing table to add or drop columns.

Q7
True / False

PostgreSQL supports partitioned tables, which allow you to divide large tables into smaller, more manageable pieces.

Q8
True / False

In PostgreSQL, CTID can be used to uniquely identify rows in a table for the duration of a transaction.

Q9
True / False

PostgreSQL does not support inheritance in tables, where a child table can inherit columns from a parent table.

Q10
True / False

In PostgreSQL, the SERIAL data type can be used to automatically generate unique identifiers for table columns.

Q11
Single Choice

Which MySQL statement is used to create a new database table?

SQL Code
_____ table_name (
 column1 datatype,
 column2 datatype,
 column3 datatype
);
Q12
Single Choice

What is the correct syntax to create a table named Employees with ID as an integer primary key in MySQL?

SQL Code
CREATE TABLE Employees (
 ID INT _____ PRIMARY KEY,
 Name VARCHAR(50)
);
Q13
Single Choice

Which MySQL clause is used to remove a table from the database?

Q14
Single Choice

What is the purpose of the IF NOT EXISTS clause when creating a table in MySQL?

SQL Code
CREATE TABLE IF NOT EXISTS Employees (
 ID INT AUTO_INCREMENT PRIMARY KEY,
 Name VARCHAR(50)
);
Q15
Single Choice

How would you modify an existing table named Employees to add a new column Email with a VARCHAR(100) data type?

SQL Code
ALTER TABLE Employees _____ Email VARCHAR(100);
Q16
Single Choice

Which of the following MySQL statements can be used to rename an existing table from OldTable to NewTable?

SQL Code
_____ OldTable TO NewTable;
Q17
Single Choice

Which statement is used to copy the structure of an existing table named Employees into a new table called EmployeesBackup without copying the data in MySQL?

SQL Code
_____ EmployeesBackup LIKE Employees;
Q18
Single Choice

How can you ensure that a column EmployeeID in a MySQL table always contains a unique value across all rows?

Q19
Single Choice

Which MySQL statement is used to change the data type of an existing column in a table?

SQL Code
ALTER TABLE Employees _____ Name VARCHAR(255);
Q20
Single Choice

In MySQL, how would you drop a column named MiddleName from a table Employees?

SQL Code
_____ Employees DROP COLUMN MiddleName;
Q21
Multiple Choice

Which 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
);
Q22
Multiple Choice

Which SQL command would you use to add a new column to an existing table in PostgreSQL?

SQL Code
ALTER TABLE orders
ADD COLUMN order_status VARCHAR(20) NOT NULL DEFAULT 'pending';
Q23
Multiple Choice

Identify the SQL statement that correctly deletes a table from a PostgreSQL database.

SQL Code
DROP TABLE IF EXISTS sales;
Q24
Multiple Choice

Which SQL command would you use to update a specific row in a PostgreSQL table?

SQL Code
UPDATE products
SET price = 19.99
WHERE product_id = 101;
Q25
Multiple Choice

Which of the following SQL queries would you use to retrieve all rows from a PostgreSQL table?

SQL Code
SELECT * FROM customers;
Q26
Multiple Choice

Choose 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
);
Q27
Multiple Choice

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

SQL Code
ALTER TABLE customers
RENAME TO clients;
Q28
Multiple Choice

Which 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;
Q29
Multiple Choice

Identify the correct SQL command that adds a check constraint to an existing table in PostgreSQL.

SQL Code
ALTER TABLE products
ADD CONSTRAINT chk_price
CHECK (price > 0);
Q30
Multiple Choice

Which 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)
);