Insert Statement in SQL
INSERT Statement in SQL
The INSERT statement is used to add new rows (records) into a database table.
Basic Syntax:
INSERT INTO table_name (column1, column2, column3, ...)VALUES (value1, value2, value3, ...);You specify the table name.
Then the list of columns you want to insert values into.
Followed by the corresponding values in the same order.
Example:
INSERT INTO employees (name, department, salary)VALUES ('John Doe', 'Sales', 50000);This adds a new employee named John Doe to the employees table.
Inserting Multiple Rows:
INSERT INTO employees (name, department, salary)VALUES ('Alice', 'Marketing', 60000), ('Bob', 'IT', 70000), ('Charlie', 'HR', 55000);Insert Without Specifying Columns (if inserting all columns in order):
INSERT INTO employeesVALUES (1, 'David', 'Finance', 65000);Notes:
Make sure values match the data types of columns.
Columns with
AUTO_INCREMENTor default values can be omitted.If you omit columns without defaults, the query will fail.
If you want, I can help you with advanced inserts like INSERT INTO ... SELECT or prepared statements!