Inserting data into MySQL tables is easy, but I tend to forget little details once in a while. I was having the best espresso coffee and trying to remember this one. Below is how you insert a new row into a MySQL table.
Assume you created the following table:
CREATE TABLE IF NOT EXISTS mytable (
mytable_id INT AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
start_date DATE,
due_date DATE,
priority TINYINT NOT NULL DEFAULT 3,
description TEXT,
PRIMARY KEY (task_id)
);
And then you want to insert a new row into this MySQL table. Run the command below:
INSERT INTO tasks(title,priority)
VALUES('Learn MySQL INSERT Statement',1);
You should get the below from MySQL:
1 row(s) affected
That’s all! Contact me if you need help. Write in the comments section if you have questions.