MYSQL Tutorial



MySQL INSERT INTO


MySQL INSERT INTO Query

The INSERT INTO statement is used to add new rows (records) to a table in MySQL.

πŸ”Ή Syntax

INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
  

πŸ”Ή Example

Suppose we have this products table:

CREATE TABLE products (
  product_id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(255),
  description TEXT,
  price FLOAT,
  in_stock BOOLEAN,
  created_at DATE
);
  

We can insert a new product like this:

INSERT INTO products (name, description, price, in_stock, created_at)
VALUES ('Wireless Mouse', 'Ergonomic wireless mouse', 15.99, TRUE, '2025-05-16');
  

πŸ”Ή Notes

  • If you specify the columns, the values must be in the same order.
  • If a column is auto-incremented (like product_id), you don’t need to insert a value for it.
  • Strings and dates should be enclosed in single quotes ' '.
Tip: You can insert multiple rows in a single query by separating values with commas.

πŸ”Ή Insert Multiple Rows

INSERT INTO products (name, description, price, in_stock, created_at)
VALUES
  ('Keyboard', 'Mechanical keyboard', 29.99, TRUE, '2025-05-15'),
  ('USB Cable', '1 meter USB-C cable', 5.49, TRUE, '2025-05-10');
  

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review