TrainityTrainity
All ideas

Foreign key constraint

I am having difficulty in understanding foreign key constraint. All my queries are not running. I want to clear few doubts regarding the foreign key for better understanding. Is it necessary to have primary key columns in both the tables to execute foriegn key? Is it necessary to have a similar data columns in both the tables to exceute foreign key? Can we exceute the foriegn key if one table has primary key column and another table doesn't? do we have to execute foreign key only between the primary key columns to link the tables or we can execute it with the other columns which don't have primary key? Can we link two columns in a same table using foreign key even if the data is not similar and they are not primary key columns?