SQL Insert, Update, and Delete INSERT Statement
The SQL INSERT, UPDATE, and DELETE statements are used to manipulate the data in a database. In this article, we will focus on the INSERT statement.
INSERT Statement Syntax
The basic syntax of the INSERT statement is as follows:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
INSERT Statement Example
Suppose we have a table named "students" with columns "id", "name", "age", and "gender". We want to insert a new record with id = 1, name = "John", age = 20, and gender = "M".
The INSERT statement for this would be:
INSERT INTO students (id, name, age, gender)
VALUES (1, 'John', 20, 'M');
INSERT Statement Output
The output of the above INSERT statement would be:
Query OK, 1 row affected
INSERT Statement Explanation
The INSERT statement is used to add new records to a table. The table name must be specified in the INSERT INTO clause. The column names and values are specified in the VALUES clause.
INSERT Statement Use
The INSERT statement is used when you want to add new data to a table.
INSERT Statement Important Points
- The number of columns in the INSERT statement should match the number of values in the VALUES clause.
- The order of the columns and values must match.
- String values must be enclosed in single quotes.
INSERT Statement Summary
The SQL INSERT statement is used to add new records to a table. It requires the table name, column names, and values to be specified. Important points to remember include ensuring that the number of columns and values match, and that string values are enclosed in single quotes.