Support Online
Skip to main content

Guide to Adding Data with SQL INSERT INTO Command

Meta Description: Learn how to insert a new record into a table with the SQL INSERT INTO command, copy data with a SELECT query, and automatically assign values.
You can make practical applications with MySQL examples.

🎯 What Will You Learn in This Guide?

In this guide, you will learn three different methods of inserting data into the database in SQL:

  • Adding records manually with VALUES
  • Transfer data from another table with SELECT query
  • Automatic value assignment with AUTO_INCREMENT and DEFAULT

You'll also see the advantages of bulk insertion in terms of column order, NULL behavior, and performance.


🧠 Technical Summary

  • Main Topic: SQL INSERT INTO command
  • Purpose: Adding new records to tables
  • Scope:
    1. Add single line or multiple lines
    2. Copying data from another table
    3. Adding data with auto valued columns
    4. NULL and DEFAULT behavior
    5. Multiple insertion strategies for performance

🧱 1. Preparing the Tables

Create a new database and table:

CREATE DATABASE insertDB;
USE insertDB;

CREATE TABLE fabrikaCalisanlari (
ad VARCHAR(30),
pozisyon VARCHAR(30),
departman VARCHAR(20),
saatlikUcret DECIMAL(5,2),
iseBaslamaTarihi DATE
);

💬 FactoryEmployees table holds employee information.


🧩 2. Adding Manual Data (Using VALUES)

Adding a Single Line

INSERT INTO fabrikaCalisanlari
(ad, pozisyon, departman, saatlikUcret, iseBaslamaTarihi)
VALUES
('Ayla', 'Kalıp Ustası', 'Yönetim', 35.75, '2019-06-15');

💬 The employee named Ayla is added to the table.

Even If the Column Order Is Different


INSERT INTO fabrikaCalisanlari
(departman, saatlikUcret, iseBaslamaTarihi, ad, pozisyon)
VALUES
('Üretim', 22.10, '2020-03-01', 'Barış', 'Montajcı');

💬 The column order may be different, but the value order must be compatible.

Insertion with Missing Columns (NULL Behavior)


INSERT INTO fabrikaCalisanlari
(ad, pozisyon, saatlikUcret)
VALUES
('Can', 'Kalite Kontrol', 28.00);

💬 Department and date fields are automatically NULL. Note: If there is a NOT NULL constraint, it will give an error.

Bulk Adding Data

INSERT INTO fabrikaCalisanlari
VALUES
('Deniz', 'Kaynakçı', 'Üretim', 30.50, '2019-01-20'),
('Ece', 'Test Analisti', 'Kalite', 26.00, '2021-08-05');

💬 Adds multiple records at once — this is much more efficient in terms of performance.


📋 3. Copying Data with SELECT

INSERT INTO ... SELECT is used to move or back up records from one table to another table.

Creating a New Table

CREATE TABLE depoCalisanlari (
ad VARCHAR(30),
saatlikUcret DECIMAL(5,2),
iseBaslamaTarihi DATE
);
Copying Data

INSERT INTO depoCalisanlari
SELECT ad, saatlikUcret, iseBaslamaTarihi
FROM fabrikaCalisanlari
WHERE departman NOT LIKE 'Ü%';

💬 Employees whose departments do not start with "Ü" are added to the warehouseEmployees table. Note: Using SELECT is ideal for large-scale data migrations.


⚙️ 4. Automatic Data Insertion (AUTO_INCREMENT & DEFAULT)

Some columns may retrieve data automatically. AUTO_INCREMENT produces an ID that increases with each record, while DEFAULT assigns a default value to unspecified columns.

Table Definition

CREATE TABLE stajyerler (
stajyerID INT AUTO_INCREMENT PRIMARY KEY,
departman VARCHAR(20) DEFAULT 'Üretim',
ad VARCHAR(30)
);
Adding Data

INSERT INTO stajyerler (ad)
VALUES ('Emre'), ('Fatoş'), ('Gökhan');

💬 ID increases automatically, department value automatically becomes "Production".

Overriding the Default Value


INSERT INTO stajyerler (ad, departman)
VALUES
('Hakan', 'Yönetim'),
('İrem', DEFAULT);

💬 The DEFAULT value “Production” is assigned for İrem.


❓ Frequently Asked Questions (FAQ)

  1. What is the advantage of using SELECT instead of VALUES?

With SELECT, you can move thousands of records at once and speed up data transfer.

  1. What does AUTO_INCREMENT do?

It automatically generates a unique ID for each record, no manual entry required.

  1. What happens to columns whose DEFAULT value is omitted?

The default value is assigned; If it does not exist and is NOT NULL, it is NULL.

  1. Why is it important to specify column names with the table name?

Prevents confusion in queries containing JOIN (example: factoryCalisanlari.ad).

  1. How does adding multiple records affect performance?

Adding multiple records in a single query reduces communication with the server — it's much faster.


☁️ Conclusion and Recommendation

In this guide, you learned the manual, SELECT-based and automatic insertion methods of the SQL INSERT INTO command. Now you can safely apply both single and bulk data insertion operations.

💡 Test all examples immediately in the MySQL environment on GenixNode. Securely manage your developments on a scalable cloud server. 🚀