The INSERT statement is used to add new rows into a table.
1.Basic Syntax
- table_name → Name of the table
- (column1, column2, …) → Columns to insert data into
- VALUES → The values corresponding to columns
- Columns must match the values in number and data type.
2.Example Table
Employees Table
| EmployeeID | Name | Department | Salary |
|---|---|---|---|
| 1 | John | IT | 5000 |
| 2 | Jane | HR | 4500 |
3.Insert a Single Row
Result:
| EmployeeID | Name | Department | Salary |
|---|---|---|---|
| 1 | John | IT | 5000 |
| 2 | Jane | HR | 4500 |
| 3 | Mike | IT | 6000 |
4.Insert Multiple Rows
✅ Multiple rows can be inserted in one statement.
5.Insert Data Without Specifying Columns
Must provide values for all columns in the exact order.
⚠ Not recommended; better to specify columns.
6.Insert Data from Another Table
- Copies selected rows from Employees into EmployeesBackup
7.Insert with DEFAULT Values
If a column has a default value:
- Salary will use the default value (if defined)
8.Insert Using SELECT (Advanced)
- Can transform data during insert
9.Identity Column Consideration
If EmployeeID is an IDENTITY column:
- SQL Server automatically generates EmployeeID
- To insert explicit values into IDENTITY, use:
