Search code examples
sqlmysqlsaveautosave

how to save manually and automatically on mysql


MySQL, save datas manually and automatically I need to create a MySQL table to store the title of bachelor theses and automatically store the posting date of the thesis. Which command do you use to save manually and how to save automatically?

Maybe I can use 'commit' but I am not sure how to use it


Solution

  • This creates the table:

    CREATE TABLE bachelor_theses (
        id INT AUTO_INCREMENT PRIMARY KEY,
        title VARCHAR(255),
        posting_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    

    This will insert(save) the title in a new row and will automatically add the current timestamp.

    INSERT INTO bachelor_theses (title) VALUES ('Some Thesis Title');
    

    you will run this insert manually, but it automatically adds the new row.

    No need to commit. This term is used in more complex scenarios.