wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

DDL Commands Quiz

Total questions: 25

Worksheet time: 14mins

Name
Class
Date
1.

What command is used to create a new table in SQL?

a)

UPDATE

b)

CREATE

c)

DELETE

d)

INSERT

2.

Which command is used to modify an existing table structure?

a)

DROP

b)

SELECT

c)

ADD

d)

ALTER

3.

What is the purpose of the DROP command?

a)

To remove a table

b)

To add a new column

c)

To retrieve data

d)

To change data types

4.

Which SQL command would you use to add a new column to a table?

a)

SELECT

b)

ALTER

c)

INSERT

d)

UPDATE

5.

What does the TRUNCATE command do?

a)

Updates existing records

b)

Adds a new record

c)

Deletes a table

d)

Removes all records from a table

6.

Which command is used to define a new database?

a)

NEW DATABASE

b)

DEFINE DATABASE

c)

CREATE DATABASE

d)

ADD DATABASE

7.

What is the correct syntax to rename a table?

a)

ALTER TABLE old_name RENAME TO new_name

b)

RENAME TABLE old_name TO new_name

c)

CHANGE TABLE old_name TO new_name

d)

UPDATE TABLE old_name SET name = new_name

8.

Which command would you use to set a primary key on a table?

a)

SET PRIMARY KEY

b)

ADD PRIMARY KEY

c)

CREATE PRIMARY KEY

d)

ALTER TABLE ADD PRIMARY KEY

9.

What command is used to remove a column from a table?

a)

REMOVE COLUMN

b)

DELETE COLUMN

c)

DROP COLUMN

d)

ALTER TABLE DROP COLUMN

10.

Which SQL command is used to change the data type of a column?

a)

CHANGE

b)

MODIFY

c)

ALTER

d)

UPDATE

11.

What is the purpose of the UNIQUE constraint?

a)

To create a foreign key

b)

To set a default value

c)

To ensure all values in a column are different

d)

To allow duplicate values

12.

Which command is used to create an index on a table?

a)

ALTER INDEX

b)

INDEX TABLE

c)

ADD INDEX

d)

CREATE INDEX

13.

What does the command 'ALTER TABLE users DROP COLUMN email' do?

a)

Changes the email column in the users table

b)

Adds a new email column to the users table

c)

Renames the email column in the users table

d)

Removes the email column from the users table

14.

Which command would you use to add a foreign key constraint?

a)

SET FOREIGN KEY

b)

CREATE FOREIGN KEY

c)

ALTER TABLE ADD CONSTRAINT

d)

ADD FOREIGN KEY

15.

What is the purpose of the NOT NULL constraint?

a)

To set a default value

b)

To ensure a column cannot have null values

c)

To create a unique index

d)

To allow null values in a column

16.

Which command is used to change the name of a database?

a)

UPDATE DATABASE

b)

CHANGE DATABASE

c)

ALTER DATABASE

d)

RENAME DATABASE

17.

What does the command 'CREATE TABLE orders (id INT PRIMARY KEY)' do?

a)

Creates a new table named orders with a primary key

b)

Creates a new database named orders

c)

Adds a primary key to an existing table

d)

Removes the orders table

18.

Which command is used to set a default value for a column?

a)

SET DEFAULT

b)

ALTER TABLE SET DEFAULT

c)

ADD DEFAULT

d)

ALTER TABLE column_name SET DEFAULT value

19.

What is the purpose of the CHECK constraint?

a)

To enforce a condition on a column

b)

To create a foreign key

c)

To ensure uniqueness

d)

To set a default value

20.

Perintah SQL berikut digunakan untuk membuat tabel users. Bagian manakah yang berfungsi sebagai primary key?

CREATE TABLE users(

id_user serial not null primary key,

fullname varchar(50) not null,

username varchar(50) UNIQUE not null,

email varchar(50) UNIQUE not null,

password varchar(50) not null,

role user_role not null default 'customer',

created_at timestamp default current_timestamp,

updated_at timestamp default current_timestamp

);

a)

fullname

b)

username

c)

id_user

d)

role

21.

Jika ingin menambahkan kolom phone_number dengan tipe data varchar(20) pada tabel users, perintah yang benar adalah …

a)

ALTER TABLE users ADD COLUMN phone_number varchar(20);

b)

ALTER TABLE users ADD phone_number varchar(20);

c)

MODIFY TABLE users ADD COLUMN phone_number varchar(20);

d)

UPDATE TABLE users ADD COLUMN phone_number varchar(20);

22.

Perintah SQL untuk menghapus kolom updated_at dari tabel users adalah …​ (a)  

Choose from the below words
ALTER TABLE users DROP COLUMN updated_at;
ALTER TABLE users DROP updated_at;
ALTER TABLE users REMOVE COLUMN updated_at;
DELETE COLUMN updated_at FROM users;
23.

Jika ingin mengubah tipe data kolom password dari menjadi , perintah yang benar adalah …​ (a)  

Choose from the below words
ALTER TABLE users ALTER COLUMN password TYPE varch
ALTER TABLE users MODIFY password varchar(100);
ALTER TABLE users CHANGE password varchar(100);
ALTER users ALTER COLUMN password varchar(100);
24.

Perintah SQL berikut digunakan untuk apa?

a)

Menghapus semua data di tabel users tetapi struktur tabel tetap ada

b)

Menghapus tabel users beserta seluruh data dan dependensi yang berelasi

c)

Menghapus hanya primary key pada tabel users

d)

Menghapus hanya foreign key yang ada pada tabel users

25.

Jika ingin memberikan constraint UNIQUE pada kolom fullname di tabel users, perintah yang benar adalah …​

​ ​ ​

​ (a)  

Choose from the below words
ALTER TABLE users ADD CONSTRAINT unique_fullname U
ALTER TABLE users UNIQUE(fullname);
ALTER users ADD UNIQUE(fullname);