Professional Documents
Culture Documents
com/academy
m
CREATE TABLE statement
er as
• Evaluate a business problem requiring the addition of a PRIMARY KEY and FOREIGN
co
KEY constraint and write the code to execute the change
eH w
o.
Vocabulary
rs e
Identify the vocabulary word for each definition below.
ou urc
On delete cascade Allows a foreign key row that is referenced to a primary
key row to be deleted
o
values
ar stu
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
is
Try It / Solve It
sh
This study source was downloaded by 100000809939014 from CourseHero.com on 05-05-2021 13:36:14 GMT -05:00
https://www.coursehero.com/file/46996684/DP-14-2-Practice-Ethan-Vijudocx/
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
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.
animal_id NUMBER(6) PK
Name VARCHAR2(25)
license_tag_number NUMBER(10)
UK
admit_date DATE NOT NULL
adoption_id NUMBER(5),
m
vaccination_date DATE NOT NULL
er as
co
eH w
3. Create the animals table. Write the syntax you will use to create the table.
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
4. Enter one row into the table. Execute a SELECT * statement to verify your input. Refer to
the graphic below for input.
is
Th
This study source was downloaded by 100000809939014 from CourseHero.com on 05-05-2021 13:36:14 GMT -05:00
https://www.coursehero.com/file/46996684/DP-14-2-Practice-Ethan-Vijudocx/
5. Write the syntax to create a foreign key (adoption_id) in the animals table that has a
corresponding primary- key reference in the adoptions table. Show both the column-level
and table-level syntax. Note that because you have not actually created an adoptions
table, no adoption_id primary key exists, so the foreign key cannot be added to the animals
m
table.
er as
co
Table:
eH w
Alter table animals
o.
Add adoption_id number(6) constraint animals_fk references animals(adoption_id)
rs e
ou urc
Column:
Alter table animals
Modify adoption_id number(6) constraint animals_fk references animals(adoption_id)
o
aC s
vi y re
6. What is the effect of setting the foreign key in the ANIMAL table as:
a. ON DELETE CASCADE
i The rows in the child table will be deleted when the rows in the parent table are
ed d
deleted
ar stu
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
This study source was downloaded by 100000809939014 from CourseHero.com on 05-05-2021 13:36:14 GMT -05:00
https://www.coursehero.com/file/46996684/DP-14-2-Practice-Ethan-Vijudocx/
Powered by TCPDF (www.tcpdf.org)