What are the best practices for structuring database tables to efficiently store and retrieve comments related to specific images in PHP?

When storing comments related to specific images in a database, it is important to have a well-structured database table that efficiently stores and retrieves the data. One common approach is to have a table for images and a separate table for comments, with a foreign key linking comments to the corresponding image. This allows for easy retrieval of comments for a specific image and ensures data integrity.

CREATE TABLE images (
    id INT PRIMARY KEY,
    image_url VARCHAR(255)
);

CREATE TABLE comments (
    id INT PRIMARY KEY,
    image_id INT,
    comment TEXT,
    FOREIGN KEY (image_id) REFERENCES images(id)
);