Q8
Single ChoiceHow would you create a table with a composite primary key in MySQL?
This syntax correctly defines a composite primary key consisting of order_id and product_id.
Q11
True / FalseIn MySQL, the CREATE TABLE statement is used to create a new database.
The CREATE TABLE statement is used to create a new table, not a database. The CREATE DATABASE statement is used to create a new database.
Q12
True / FalseThe VARCHAR datatype in MySQL requires a length specification when creating a table.
In MySQL, the VARCHAR datatype requires a length to be specified to determine the maximum number of characters that can be stored.
Q13
True / FalseYou can use the CREATE TABLE statement in MySQL to create a table without specifying any columns.
When creating a table in MySQL, you must specify at least one column.
Q14
True / FalseIn MySQL, the PRIMARY KEY constraint can be applied to more than one column in a table.
MySQL allows the PRIMARY KEY constraint to be applied to multiple columns, creating a composite primary key.
Q15
True / FalseThe DEFAULT keyword in MySQL is used to set a default value for a column when creating a table.
The DEFAULT keyword sets a default value for a column that will be used if no value is specified during insertion.
Q16
True / FalseIn MySQL, columns defined with the NOT NULL constraint can accept NULL values.
The NOT NULL constraint ensures that a column cannot accept NULL values.
Q17
True / FalseIn MySQL, the AUTO_INCREMENT attribute can be used on any column type.
The AUTO_INCREMENT attribute is typically used on integer columns to automatically generate unique values.
Q18
True / FalseIn MySQL, you can create a table with a FOREIGN KEY constraint that references a column in the same table.
The AUTO_INCREMENT attribute is typically used on integer columns to automatically generate unique values.
Q19
True / FalseThe ENGINE keyword in MySQL is used in the CREATE TABLE statement to specify the storage engine for the table.
The ENGINE keyword specifies the storage engine (such as InnoDB or MyISAM) for the table.
Q20
True / FalseIn MySQL, creating a table with a TEXT column is more efficient than using a VARCHAR column for large text data.
The TEXT datatype is designed for storing large amounts of text data efficiently, while VARCHAR is suitable for shorter strings and requires a length specification.
Q21
Multiple ChoiceIdentify the correct CREATE TABLE statement for defining a table with a primary key and a unique constraint.
SQL Code
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
email VARCHAR(100) UNIQUE
);
The primary key ensures each employee has a unique ID, and the unique constraint on the email column prevents duplicate email addresses.
Q22
Multiple ChoiceSelect the correct CREATE TABLE statement that includes a foreign key constraint.
SQL Code
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT,
order_date DATE,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);
The foreign key constraint on the customer_id column establishes a relationship between the orders and customers tables.
Q23
Multiple ChoiceChoose the correct CREATE TABLE statement that sets a default value for a column.
SQL Code
CREATE TABLE products (
product_id INT PRIMARY KEY,
product_name VARCHAR(100),
category VARCHAR(50) DEFAULT 'General',
price DECIMAL(10, 2)
);
The category column has a default value of 'General', which is used if no other value is provided during the insert operation.
Q24
Multiple ChoiceWhich CREATE TABLE statement correctly defines a table with a composite primary key?
SQL Code
CREATE TABLE order_items (
order_id INT,
product_id INT,
quantity INT,
PRIMARY KEY (order_id, product_id)
);
A composite primary key is defined using multiple columns, in this case, order_id and product_id together form the primary key.
Q25
Multiple ChoiceDetermine the correct CREATE TABLE statement that includes a check constraint.
SQL Code
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
salary DECIMAL(10, 2),
CHECK (salary > 0)
);
The check constraint ensures that the salary value is always greater than 0, preventing invalid data entry.
Q26
Multiple ChoiceSelect the correct CREATE TABLE statement that defines a table with an auto-incrementing primary key.
SQL Code
CREATE TABLE invoices (
invoice_id INT AUTO_INCREMENT PRIMARY KEY,
customer_id INT,
invoice_date DATE,
amount DECIMAL(10, 2)
);
The AUTO_INCREMENT keyword ensures that each new invoice has a unique, automatically incremented ID.
Q27
Multiple ChoiceWhich CREATE TABLE statement correctly specifies a table with multiple foreign keys?
SQL Code
CREATE TABLE student_courses (
student_id INT,
course_id INT,
enrollment_date DATE,
PRIMARY KEY (student_id, course_id),
FOREIGN KEY (student_id) REFERENCES students(student_id),
FOREIGN KEY (course_id) REFERENCES courses(course_id)
);
This table links students to courses with a composite primary key and two foreign keys referencing other tables.
Q28
Multiple ChoiceIdentify the CREATE TABLE statement that includes a column with a NOT NULL constraint.
SQL Code
CREATE TABLE departments (
department_id INT PRIMARY KEY,
department_name VARCHAR(100) NOT NULL,
manager_id INT
);
The NOT NULL constraint ensures that the department_name cannot be null, making it a required field.
Q29
Multiple ChoiceChoose the CREATE TABLE statement that defines a table with a column using the ENUM data type.
SQL Code
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
employment_status ENUM('Active', 'Inactive', 'On Leave')
);
The ENUM data type restricts the values of the employment_status column to 'Active', 'Inactive', or 'On Leave'.
Q30
Multiple ChoiceDetermine the CREATE TABLE statement that correctly uses a column alias within the statement.
SQL Code
CREATE TABLE inventory (
product_id INT PRIMARY KEY,
product_name VARCHAR(100),
quantity_in_stock INT AS qty_stock,
price DECIMAL(10, 2)
);
Column aliases are used to give a column a temporary name. However, in MySQL, column aliases are typically used in SELECT statements, not in table definitions.