SQL INSERT INTO

SQL INSERT INTO Statement (Beginner → Advanced)
The INSERT INTO statement in SQL is used to add new records (rows) into a table.
It is one of the most frequently used SQL commands and is very important for interviews and real projects.
What is INSERT INTO?
INSERT INTOis used to insert new data into a table.
or
Insert Values into All Columns
Table: students
How to Insert Data in SQL
- Order of values must match column order
- Warning: Not recommended if table structure changes
Adding Data into Specific Columns (Recommended)
markswill beNULLorDEFAULT- Safer and clearer
Ways to Insert Multiple Rows at Once
- Faster than multiple
INSERTstatements - Very common in real projects
Using DEFAULT Values While Inserting Data
- Uses column’s default value
Storing NULL Values in SQL Tables
- Allowed only if column is not
NOT NULL
Copying Data from Another Table in SQL
- Inserts result of a
SELECTquery - Used in data migration & reporting
Adding Current Date and Time Automatically
- Automatically stores current date & time
Using a Subquery to Insert Records
- Advanced but very useful
INSERT INTO vs UPDATE
| Feature | INSERT | UPDATE |
|---|---|---|
| Adds new row | Yes | No |
| Modifies existing row | No | Yes |
Uses WHERE | No | Yes |
Common Mistakes
- Column count ≠ value count
- Wrong data type
- Missing quotes for strings
- Inserting
NULLintoNOT NULLcolumn - Forgetting column list
Interview Questions (Must Prepare)
What is
INSERT INTOused for?Difference between inserting all columns vs specific columns?
How to insert multiple rows?
Can we insert data using
SELECT?What happens if column allows
NULL?Difference between
INSERTandUPDATE?
Real-Life Use Cases
User registration
Order creation
Logging events
Data migration
Importing CSV data
Summary
INSERT INTOadds new records to a table- Can insert single or multiple rows
- Supports
DEFAULT,NULL, and subqueries - Safer to specify column names
- Core command for database operations & interviews
