• Introduction
  • 1. How to Retrieve Data From a Single Table
  • 2. How to Retrieve Data from Multiple Tables
  • 3. Using Functions
  • 4. How to Insert, Update, Delete Data in Tables
  • 5. Summary Queries and Aggregate Functions
  • 6. Working With Subqueries
  • 7. SQL Views
  • 8. SQL Indexes
  • Glossary
  • Index
  • Download
  • Translations
  • 4.1

    The INSERT Clause With a Column List

    The INSERT Clause With a Column List

    • You can INSERT single or multiple rows at a time.
    • An INSERT with a column list DOES NOT require you to provide a value for each column. If you do not want to provide a value for a specific column, you do not have to include it in the column list. For columns that allow null values, the system will automatically provide a null value for you.
    • If you want a column that provides a default value such as an auto-increment column to be populated with the default value, you do not need to list the column in the column list. The system will automatically provide the default value.
    • When coding with a column list, the columns may appear in any order as long as the VALUES list matches the order of the column list.

    Below is a basic example of an INSERT statement with a column list:

    1    USE world;
    2    INSERT INTO city 
    3        (name, countryCode, district, population) 
    4    VALUES 
    5        ("San Felipe", "CHL", "Valparaiso", 64126);



    Results of the Insert:


    INSERT INTO city

    (name, countryCode, district, population) 


    ("San Felipe", "CHL", "Valparaiso", 64126);

    This content is provided to you freely by BYU-I Books.

    Access it online or download it at https://books.byui.edu/learning_mysql/the_insert_clause_wi.