What is the best practice for linking two MySQL tables, one for news and one for comments, using unique IDs for each entry?

When linking two MySQL tables, one for news and one for comments, using unique IDs for each entry, the best practice is to create a foreign key relationship between the two tables. This ensures data integrity and allows for easy retrieval of related information. To do this, you would add a column in the comments table that references the unique ID in the news table.

// Create a foreign key relationship between the news and comments tables
$sql = "ALTER TABLE comments
        ADD CONSTRAINT fk_news_id
        FOREIGN KEY (news_id)
        REFERENCES news(id)
        ON DELETE CASCADE";

// Execute the SQL query
mysqli_query($conn, $sql);