INSERT Statement

The INSERT statement is used to add new records to a table. You can specify values for one or more columns.

Examples of Using INSERT

Scenario 1: Inserting a Full Row

INSERT INTO FreedomFighters (FighterID, Name, City, BirthDate, Contribution)
VALUES (1, 'Karthick AG', 'Madurai', '1985-04-15', 'Social Activist');

Output:

Record added successfully to the FreedomFighters table.

Scenario 2: Inserting Partial Row

INSERT INTO FreedomFighters (Name, City)
VALUES ('Durai', 'Coimbatore');

Output:

Record with Name and City added. Other columns are set to default or NULL.

Do's and Don'ts

Do's

  • Specify values for all required columns to avoid errors.
  • Use transactions when inserting multiple records to maintain data integrity.
  • Check for duplicates before inserting if uniqueness is a requirement.

Don'ts

  • Don't insert data without considering foreign key constraints.
  • Don't omit columns with NOT NULL constraints without default values.
  • Don't insert records in bulk without proper indexing and performance testing.