The INSERT INTO statement in SQL is used to add new rows of data to a table. Here’s a detailed tutorial on how to use the INSERT INTO statement effectively.
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
Assume you have a table named employees with columns first_name, last_name, age, and department.
INSERT INTO employees (first_name, last_name, age, department)
VALUES ('John', 'Doe', 30, 'Engineering');
2. Inserting Data into All Columns
If you want to insert values into all columns, you can omit the column names:
INSERT INTO employees
VALUES ('Jane', 'Smith', 28, 'Marketing');
3. Inserting Multiple Rows
You can insert multiple rows in a single INSERT INTO statement by separating each set of values with a comma:
INSERT INTO employees (first_name, last_name, age, department)
VALUES
('Alice', 'Johnson', 35, 'HR'),
('Bob', 'Brown', 40, 'Finance');