To insert data into a table, use the following syntax:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
table_name
: The name of the table where data is being inserted.column1
, column2
, ...: The columns in which you want to insert data.value1
, value2
, ...: The values to be inserted into the respective columns.Let’s insert a new record into the employees
table we created earlier:
INSERT INTO employees (name, email)
VALUES ('Jane Doe', 'jane@example.com');
In this example:
name
column gets the value 'Jane Doe'
.email
column gets the value 'jane@example.com'
.You can also insert multiple rows at once by separating each set of values with a comma:
INSERT INTO employees (name, email)
VALUES ('Alice', 'alice@example.com'),
('Bob', 'bob@example.com');
The INSERT INTO
statement is crucial for adding data into your MySQL tables. By specifying the columns and corresponding values, you can efficiently populate your database with the necessary records. Ensure that the values match the data types of the columns to avoid errors and maintain data integrity.