How to make a field in a table a link to another table in MySQL / MariaDB?

Let's say I'm setting up a small database in just 2 tables: feeds and feeds.

In one table, I would save the feed name and URL with identifier as a unique key.

In the second table, I would like to save some information coming from the feeds (in the example: date, name, element URL and file name). But instead of storing the name of the feed, I would like to refer to this feed field to the id of this feed in the first table.

thanks

+4
source share
1 answer

this is a quick example of how to reach your requirement ...

CREATE TABLE IF NOT EXISTS `feeds` ( `Feed_ID` int(11) NOT NULL, `Feed_Name` varchar(32) NOT NULL, `Feed_Url` varchar(255) NOT NULL, PRIMARY KEY (`Feed_ID`) ) CREATE TABLE IF NOT EXISTS `feeditems` ( `FeedItem_ID` int(11) NOT NULL, `Feed_ID` int(11) NOT NULL, `FeedItem_Date` datetime NOT NULL, `FeedItem_Title` varchar(255) NOT NULL, `FeedItem_Url` varchar(255) NOT NULL, `FeedItem_Name` varchar(255) NOT NULL, PRIMARY KEY (`FeedItem_ID`), FOREIGN KEY (`Feed_ID`) REFERENCES `feeds`(`Feed_ID`) ON DELETE CASCADE ) 
+6
source

All Articles