0% found this document useful (0 votes)
7 views6 pages

Homework1 DB programming

Homework1 DB Programming

Uploaded by

Omar Abdalah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

Homework1 DB programming

Homework1 DB Programming

Uploaded by

Omar Abdalah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1

Course: Database Programming


Homework 1
Student Name:-----------------------------------------------
Section Number:--------------------------------------------
Homework goals:
o Create and modify tables using DDL – Practice creating, altering, and dropping tables with
various data types and constraints.
o Manage data with DML – Insert, update, and delete rows in tables, including handling null
values and using special functions like SYSDATE.
o Apply constraints – Implement constraints such as PRIMARY KEY, FOREIGN KEY, and CHECK to
maintain data integrity.
o Manipulate table structure – Use the ALTER TABLE statement to add, modify, or drop
columns and constraints.

Exercise 1
Multiple-Choice Questions (MCQs)
1. What is the purpose of Data Definition Language (DDL)?
a) Retrieve data
b) Define and manage database structure
c) Control access to data
d) Insert new data
Answer:
2. Which of the following is a DDL operation?
a) SELECT
b) UPDATE
c) CREATE
d) INSERT
Answer:
3. What is the basic unit of storage in a database?
a) Table
b) Column
c) Sequence
d) Index
Answer:

1
2

4. What must all table names begin with?


a) A number
b) A letter
c) A special character
d) A symbol
Answer:
5. Which data type is used for storing variable-length character data?
a) CHAR
b) VARCHAR2
c) BLOB
d) CLOB
Answer:
6. Which SQL statement is used to create a table?
a) ALTER TABLE
b) DROP TABLE
c) CREATE TABLE
d) SELECT TABLE
Answer:
7. What constraint enforces unique values in a column?
a) PRIMARY KEY
b) UNIQUE
c) FOREIGN KEY
d) CHECK
Answer:
8. What is the function of a FOREIGN KEY constraint?
a) Ensures a column has only unique values
b) Establishes a link between tables
c) Prevents null values in a column
d) Ensures data integrity
Answer:
9. Which DML statement is used to insert new rows?
a) UPDATE
b) DELETE
c) SELECT
d) INSERT
Answer:
10. What is the purpose of the UPDATE statement?
a) Add new rows
b) Remove rows
c) Modify existing rows

2
3

d) Retrieve data
Answer:
11. Which statement removes all rows but keeps the structure of the table?
a) DELETE
b) DROP
c) TRUNCATE
d) REMOVE
Answer: c
12. Which data type is best for storing large binary data such as images?
a) VARCHAR2
b) NUMBER
c) BLOB
d) CLOB
Answer:
13. Which command adds a new column to an existing table?
a) ALTER TABLE and ADD COLUMN
b) ALTER TABLE
c) MODIFY COLUMN
d) DROP COLUMN
Answer:
14. Which command is used to delete a table from the database?
a) DROP TABLE
b) DELETE TABLE
c) REMOVE TABLE
d) CLEAR TABLE
Answer:
15. Which statement changes the structure of an existing table?
a) CREATE TABLE
b) ALTER TABLE
c) DELETE TABLE
d) TRUNCATE TABLE
Answer:
16. What is the default value used in a CREATE TABLE statement?
a) An expression or function
b) A column from another table
c) Any pseudo column
d) A random number
Answer:

3
4

17. Which clause is used to rename a column in a table?


a) ALTER COLUMN
b) ALTER and RENAME COLUMN
c) MODIFY COLUMN
d) CHANGE COLUMN
Answer:
18. What does the CHECK constraint do?
a) Ensures column values meet a specific condition
b) Prevents null values
c) Ensures uniqueness
d) Links tables together
Answer:
19. What statement is used to add new rows with some null values?
a) DELETE
b) INSERT
c) UPDATE
d) SELECT
Answer:
20. Which statement allows updating more than one row at once?
a) SELECT
b) DELETE
c) INSERT
d) UPDATE
Answer:

Exercise 2
True/False Questions
1. DDL commands can be used to modify existing rows.
Answer:
2. A PRIMARY KEY constraint automatically enforces NOT NULL.
Answer:
3. The DROP TABLE command removes both data and the table structure.
Answer:
4. A UNIQUE constraint allows duplicate values.
Answer:
5. A column must be specified when using the DELETE statement.
Answer:

4
5

6. VARCHAR2 is used for storing variable-length character data.


Answer:
7. ALTER TABLE is used to delete a table.
Answer:
8. You can specify a default value for a column in the CREATE TABLE statement.
Answer:
9. The TRUNCATE statement can be easily undone like a DELETE statement?
Answer:
10. The CHECK constraint can reference columns in other tables.
Answer:
11. SYSDATE can be used to insert the current date and time into a table.
Answer:
12. A FOREIGN KEY constraint ensures that the child table column values match a
value in the parent table.
Answer:
13. The DROP command is used to add new rows to a table.
Answer:
14. The INSERT statement can be used to add multiple rows at once.
Answer:
15. DML statements include SELECT, INSERT, UPDATE, and DELETE.
Answer:
16. The NOT NULL constraint ensures that a column cannot have a null value.
Answer:
17. A column name must be specified when using the TRUNCATE statement.
Answer:
18. You can create a new column in an existing table with the ALTER TABLE
statement.
Answer:
19. A table can have more than one PRIMARY KEY.
Answer:
20. The DELETE statement removes all rows and the structure of a table.
Answer:

5
6

Exercise 3
Match each SQL keyword in Column B with the appropriate description number in Column A.
Write the corresponding number in the space provided in Column C.

Column B (SQL Column C (Your


Column A (Description)
Keyword) Answer)

1. Adds new data to a table. A) DELETE

2. Modifies existing records in a table. B) INSERT

3. Removes all rows from a table while keeping


C) TRUNCATE
its structure.

4. Creates a new table in the database. D) CREATE

5. Changes the structure of an existing table. E) ALTER

You might also like