Font size
WorksheetsDDL Commands Quiz
Total questions: 25
Worksheet time: 14mins
What command is used to create a new table in SQL?
UPDATE
CREATE
DELETE
INSERT
Which command is used to modify an existing table structure?
DROP
SELECT
ADD
ALTER
What is the purpose of the DROP command?
To remove a table
To add a new column
To retrieve data
To change data types
Which SQL command would you use to add a new column to a table?
SELECT
ALTER
INSERT
UPDATE
What does the TRUNCATE command do?
Updates existing records
Adds a new record
Deletes a table
Removes all records from a table
Which command is used to define a new database?
NEW DATABASE
DEFINE DATABASE
CREATE DATABASE
ADD DATABASE
What is the correct syntax to rename a table?
ALTER TABLE old_name RENAME TO new_name
RENAME TABLE old_name TO new_name
CHANGE TABLE old_name TO new_name
UPDATE TABLE old_name SET name = new_name
Which command would you use to set a primary key on a table?
SET PRIMARY KEY
ADD PRIMARY KEY
CREATE PRIMARY KEY
ALTER TABLE ADD PRIMARY KEY
What command is used to remove a column from a table?
REMOVE COLUMN
DELETE COLUMN
DROP COLUMN
ALTER TABLE DROP COLUMN
Which SQL command is used to change the data type of a column?
CHANGE
MODIFY
ALTER
UPDATE
What is the purpose of the UNIQUE constraint?
To create a foreign key
To set a default value
To ensure all values in a column are different
To allow duplicate values
Which command is used to create an index on a table?
ALTER INDEX
INDEX TABLE
ADD INDEX
CREATE INDEX
What does the command 'ALTER TABLE users DROP COLUMN email' do?
Changes the email column in the users table
Adds a new email column to the users table
Renames the email column in the users table
Removes the email column from the users table
Which command would you use to add a foreign key constraint?
SET FOREIGN KEY
CREATE FOREIGN KEY
ALTER TABLE ADD CONSTRAINT
ADD FOREIGN KEY
What is the purpose of the NOT NULL constraint?
To set a default value
To ensure a column cannot have null values
To create a unique index
To allow null values in a column
Which command is used to change the name of a database?
UPDATE DATABASE
CHANGE DATABASE
ALTER DATABASE
RENAME DATABASE
What does the command 'CREATE TABLE orders (id INT PRIMARY KEY)' do?
Creates a new table named orders with a primary key
Creates a new database named orders
Adds a primary key to an existing table
Removes the orders table
Which command is used to set a default value for a column?
SET DEFAULT
ALTER TABLE SET DEFAULT
ADD DEFAULT
ALTER TABLE column_name SET DEFAULT value
What is the purpose of the CHECK constraint?
To enforce a condition on a column
To create a foreign key
To ensure uniqueness
To set a default value
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
);
fullname
username
id_user
role
Jika ingin menambahkan kolom phone_number dengan tipe data varchar(20) pada tabel users, perintah yang benar adalah …
ALTER TABLE users ADD COLUMN phone_number varchar(20);
ALTER TABLE users ADD phone_number varchar(20);
MODIFY TABLE users ADD COLUMN phone_number varchar(20);
UPDATE TABLE users ADD COLUMN phone_number varchar(20);
Perintah SQL untuk menghapus kolom updated_at dari tabel users adalah … (a)
Jika ingin mengubah tipe data kolom password dari menjadi , perintah yang benar adalah … (a)
Perintah SQL berikut digunakan untuk apa?
Menghapus semua data di tabel users tetapi struktur tabel tetap ada
Menghapus tabel users beserta seluruh data dan dependensi yang berelasi
Menghapus hanya primary key pada tabel users
Menghapus hanya foreign key yang ada pada tabel users
Jika ingin memberikan constraint UNIQUE pada kolom fullname di tabel users, perintah yang benar adalah …
(a)
