wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

SQL Commands Quiz

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which of the following SQL statements is correct for creating a new table named Employees with columns for ID (integer, primary key), Name (variable character, max 100 characters), and HireDate (date)?

a)

MAKE TABLE Employees (ID int, Name varchar(100), HireDate date);

b)

CREATE TABLE Employees (ID int PRIMARY KEY, Name varchar(100), HireDate date);

c)

NEW TABLE Employees (ID int KEY, Name string(100), HireDate date);

d)

BUILD TABLE Employees (ID int, Name char(100), HireDate);

2.

You need to add a new column called Salary (decimal data type) to the existing Employees table. Which SQL statement should you use?

a)

INSERT COLUMN Salary DECIMAL INTO Employees;

b)

ALTER TABLE Employees ADD Salary DECIMAL(10,2);

c)

UPDATE Employees SET COLUMN Salary DECIMAL;

d)

ADD COLUMN Salary DECIMAL(10,2) TO Employees;

3.

The Name column in the Employees table is currently varchar(50). You need to increase its maximum length to 150 characters. How do you achieve this in most SQL dialects?

a)

ALTER TABLE Employees CHANGE COLUMN Name varchar(150);

b)

ALTER TABLE Employees MODIFY COLUMN Name VARCHAR(150);

c)

ALTER TABLE Employees ALTER COLUMN Name VARCHAR(150);

d)

EDIT TABLE Employees (Name VARCHAR(150));

4.

What is the key difference between the DROP TABLE command and the TRUNCATE TABLE command?

a)

DROP deletes table data but keeps the structure, while TRUNCATE removes both data and structure.

b)

DROP removes both the table structure and all its data, while TRUNCATE only deletes the data, keeping the table structure.

c)

TRUNCATE is a transaction-safe operation that can be rolled back, while DROP cannot.

d)

DROP requires a WHERE clause, while TRUNCATE does not.

5.

Which of the following is a key characteristic of the TRUNCATE TABLE statement compared to the DELETE statement without a WHERE clause?

a)

TRUNCATE is a DML operation and can be rolled back, while DELETE is DDL and cannot.

b)

TRUNCATE can be used to remove specific rows based on a condition, while DELETE removes all rows.

c)

TRUNCATE resets any auto-incrementing identity columns to their initial value, while DELETE does not.

d)

TRUNCATE operations are logged individually for each row, making them slower but safer.

6.

What is the primary risk of executing the following command? DROP TABLE Customers;

a)

It will fail if the table is currently being used by another query.

b)

It will permanently delete the Customers table and all its data, constraints, and indexes from the database.

c)

It will remove all data from the Customers table but log each row deletion, consuming significant transaction log space.

d)

It will only work if you are the database owner.

7.

You want to remove an unused column named PhoneExtension from the Employees table. Which command is correct?

a)

ALTER TABLE Employees DELETE COLUMN PhoneExtension;

b)

ALTER TABLE Employees DROP COLUMN PhoneExtension;

c)

REMOVE COLUMN PhoneExtension FROM Employees;

d)

DELETE COLUMN PhoneExtension ON Employees;

8.

You are creating an Orders table. You need to ensure the Quantity column never contains a value less than 1. Which constraint should you add to the CREATE TABLE statement?

a)

PRIMARY KEY

b)

FOREIGN KEY

c)

CHECK (Quantity >= 1)

d)

UNIQUE

9.

In many RDBMS like SQL Server, why might a user need higher privileges to run TRUNCATE TABLE compared to DELETE?

a)

Because TRUNCATE requires explicit column names to be specified.

b)

Because TRUNCATE is a Data Definition Language (DDL) command that does not log individual row deletions, making it a more powerful and less recoverable operation.

c)

Because TRUNCATE can only be run by the user who created the table.

d)

Because TRUNCATE automatically creates a backup of the table before emptying it.

10.

After running the following sequence of commands, what is the final outcome? CREATE TABLE Test (ID int); INSERT INTO Test VALUES (1); TRUNCATE TABLE Test; DROP TABLE Test;

a)

The table Test exists and is empty.

b)

The table Test and the data 1 still exist.

c)

The table Test no longer exists in the database.

d)

The command sequence fails because you cannot TRUNCATE a table with data.