Adding a FK on a populated table.
Hello all,
I have the following these two tables, already populated.
The AUTHOR_ID field is a newly added field that I need to
add in my BOOK table, which will serve as a foriegn key to
my AUTHOR table. I have come up with a script to properly
populate this field. However, when I try to add a constraint
as FK on this field, with either cascade, restrict or No action
then, the ALTER doesn't work, and throws an error.
Is it at all possible to define a FK on a field of a table
when the 2 tables are already populated?
BOOK
+----------+------------+-----------+-----------+
| ID | TITLE | VOL | AUTH_ID |
+----------+------------+-----------+-----------+
| 001 | Walk to Re | 01 | 0001 |
+----------+------------+-----------+-----------+
| 002 | Alfred Jo | 05 | 0003 |
+----------+------------+-----------+-----------+
| 003 | The Talk | 01 | 0004 |
+----------+------------+-----------+-----------+
| 004 | Kite Runner| 01 | 0001 |
+----------+------------+-----------+-----------+
AUTHOR
+----------+------------+-----------+-----------+
| ID | NAME | BORN | DIED |
+----------+------------+-----------+-----------+
| 0001 | Paul J Ark | 610 | 650 |
+----------+------------+-----------+-----------+
| 0002 | Kim Lao | 795 | 850 |
+----------+------------+-----------+-----------+
| 0003 | Ashrad Al | 1085 | 1150 |
+----------+------------+-----------+-----------+
| 0004 | Khaled A B | 1170 | 1220 |
+----------+------------+-----------+-----------+
Thanks.