How to Insert data in MySQL

1 Answer(s)
-- Assuming the users table has only three columns: first_name, last_name, and email, and in that order
INSERT INTO users VALUES ('John', 'Doe', '');

INSERT INTO users (first_name, last_name, email, birth_date, city, state)
VALUES ('John', 'Doe', '','2000-01-01','Los Angeles','CA');

Inserting Multiple Rows

You can insert multiple rows in one INSERT statement by having multiple sets of values enclosed in parentheses:

INSERT INTO users (first_name, last_name)
Answered on September 1, 2021.

If inserting a row would violate a unique constraint, there are different ways to handle it, depending on your requirements.

Using INSERT IGNORE will quietly discard the row to be inserted:

INSERT IGNORE INTO products (product_id, product_name, stocks)
VALUES (1, 'VPN Product 1', 50);
on September 1, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.