What are the best practices for storing survey data in a SQL database for easier analysis?

When storing survey data in a SQL database for easier analysis, it is important to properly structure the database tables to efficiently store and retrieve the data. One best practice is to create separate tables for survey questions, responses, and respondents, and establish relationships between them using foreign keys. This will allow for easier querying and analysis of the survey data.

CREATE TABLE surveys (
    id INT PRIMARY KEY,
    title VARCHAR(255)
);

CREATE TABLE questions (
    id INT PRIMARY KEY,
    survey_id INT,
    question_text TEXT,
    FOREIGN KEY (survey_id) REFERENCES surveys(id)
);

CREATE TABLE respondents (
    id INT PRIMARY KEY,
    name VARCHAR(255)
);

CREATE TABLE responses (
    id INT PRIMARY KEY,
    respondent_id INT,
    question_id INT,
    response_text TEXT,
    FOREIGN KEY (respondent_id) REFERENCES respondents(id),
    FOREIGN KEY (question_id) REFERENCES questions(id)
);