Day 06 – SQL INSERT INTO statement
SQL INSERT INTO statement is used to insert new records into a table. The basic syntax of an INSERT INTO statement is:
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
In this syntax, table_name is the name of the table that you want to insert records into, and column1, column2, column3, etc. are the names of the columns that you want to insert data into. The VALUES keyword is used to specify the values to be inserted into each column.
Here’s an example of an INSERT INTO statement that inserts a new record into a table named “employees”:
INSERT INTO employees (first_name, last_name, email, hire_date) VALUES ('John', 'Doe', 'email@example.com', '2022-03-31');
In this example, the INSERT INTO statement is used to insert a new record into the “employees” table with the values ‘John’ for the first_name column, ‘Doe’ for the last_name column, ‘firstname.lastname@example.org‘ for the email column, and ‘2022-03-31’ for the hire_date column.
You can also insert multiple records into a table with a single INSERT INTO statement. To do this, you simply separate each set of values with a comma. Here’s an example:
INSERT INTO employees (first_name, last_name, email, hire_date) VALUES ('Jane', 'Smith', 'email@example.com', '2022-03-30'), ('Bob', 'Johnson', 'firstname.lastname@example.org', '2022-03-29');
In this example, the INSERT INTO statement inserts two new records into the “employees” table with the specified values.
The INSERT INTO statement is a fundamental SQL statement that is used to add new records to a table. It is commonly used in conjunction with other SQL statements, such as SELECT and UPDATE, to manage and manipulate data in a database.