How can the structure of the database tables be optimized for efficient comment management in PHP?

To optimize the structure of the database tables for efficient comment management in PHP, it is essential to have a separate table for comments that is linked to the main content table using a foreign key constraint. This allows for easier retrieval, insertion, and updating of comments related to specific content items. Additionally, indexing the relevant columns can improve query performance when fetching comments.

CREATE TABLE content (
    id INT PRIMARY KEY,
    title VARCHAR(255),
    body TEXT
);

CREATE TABLE comments (
    id INT PRIMARY KEY,
    content_id INT,
    comment TEXT,
    created_at TIMESTAMP,
    FOREIGN KEY (content_id) REFERENCES content(id)
);