DP - 14 - 2 - Practice FAZRULAKMALFADILA - C2C022001
DP - 14 - 2 - Practice FAZRULAKMALFADILA - C2C022001
DP - 14 - 2 - Practice FAZRULAKMALFADILA - C2C022001
NIM : C2C022001
Kelas : Informatika A
Vocabulary
Identify the vocabulary word for each definition below.
ON DELETE CASCADE Allows a foreign key row that is referenced to a primary key
row to be deleted
Check Constraint Explicitly defines a condition that must be met
PRIMARY KEY A column or set of columns that uniquely identifies each row
in a table
NOT NULL Constraint ensures that the column contains no null values
ON DELETE SET NULL Allows a child row to remain in a table with null values
when a parent record has been deleted
FOREIGN KEY Constraint Establishes a relationship between the foreign key column and a
primary key or unique key in the same table or a different table
Try It / Solve It
2. Using the column information for the animals table below, name constraints where applicable at the table
level, otherwise name them at the column level. Define the primary key (animal_id). The
license_tag_number must be unique. The admit_date and vaccination_date columns cannot contain null
values.
3. Create the animals table. Write the syntax you will use to create the table.
4. Enter one row into the table. Execute a SELECT * statement to verify your input. Refer to the graphic
below for input.
If there is a value in animals.adoption_id, which is not present as primary key/unique key in parent table, it
will give error, so first fix it:
UPDATE animals
SET adoption_id = ( SELECT id FROM adoptions WHERE ROWNUM = 1);
or
UPDATE animals
SET adoption_id = NULL;
SELECT * FROM animals;
6. What is the effect of setting the foreign key in the ANIMAL table as:
a. ON DELETE CASCADE
When a record is deleted from the "adoptions" table that is referenced by the foreign key in the
"animals" table, the corresponding records in the "animals" table will be automatically deleted as well.
This ensures the referential integrity and maintains consistency.