Author - StudySection Post Views - 45 views
Mapping

Foreign Key Mapping

Foreign Key Mapping is the process of establishing a link between two records. Suppose I have a User and I make a table called users that has some specific ID that should be a primary key.

Foreign Key| users

An additional table named ‘vehicles’ has a listing of vehicles with descriptions such as the vehicle model, brand, color, and so on. The thing that comes to mind is that I have to establish a relationship with the vehicles’ owners. I am going to add a new column named user_id which works as a foreign key to the user’s table in the vehicles table.

Foreign Key| 
 users1

SQL Query Example:

ALTER TABLE `vehicles` ADD CONSTRAINT `user_vehicles` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

One-to-one mapping occurs when records of a primary table relate to a single record of a secondary table. For example, a relationship between the User table and the UserDetails table.

Foreign Key| users2

Another case occurs when a record is linked to multiple records. For example, users may have multiple vehicles, multiple phone numbers, multiple documents, etc.

users3

Whenever a record of a first table can reference multiple records of a second table and similarly a second table record can reference multiple records of a first table, it refers to many-to-many mapping. As an example, a product could have multiple tags and each tag may relate to multiple products.

Foreign Key

jQuery allows the user to create powerful and dynamic webpages that run without any hiccup. With StudySection, you have the liberty to choose among beginner or expert level jQuery Certification Exams to help you excel in this career field.

Leave a Reply

Your email address will not be published.