Can the same column have primary key & foreign key constraint to another column?
Table1: ID - Primary column, foreign key constraint for Table2 ID
Table2: ID - Primary column, Name
Will this be an issue if i try to delete table1 data?
Delete from table1 where ID=1000;
Thanks.
There should be no problem with that. Consider the following example:
The tables now contain:
Now we can successfully delete rows like this:
However we won’t be able to delete the following:
If we had defined the foreign key on
table1with theCASCADEoption, we would have been able to delete the parent, and all the children would get deleted automatically:If we were to repeat the previously failed
DELETE, the children rows intable1will be deleted as well as the parent row intable2: