...

/

Inserting Data

Inserting Data

This lesson teaches the various ways of inserting data in MySQL.

We'll cover the following...

Insert Data

In the previous lessons we created our example table, Actors. But a table without any data is not very useful. In this lesson we’ll learn how to add data into a table using the INSERT statement. We’ll retrieve the added rows using the SELECT keyword. We’ll learn more about using SELECT in the next lesson, but for now, it suffices to know that it is used for retrieving rows from a table.

Example Syntax

INSERT INTO table (col1, col2 … coln)

VALUES (val1, val2, … valn);

Connect to the terminal below by clicking in the widget. Once connected, the command line prompt will show up. Enter or copy and paste the command ./DataJek/Lessons/7lesson.sh and wait for the MySQL prompt to start-up.

Press + to interact
-- The lesson queries are reproduced below for convenient copy/paste into the terminal.
-- Query 1
INSERT INTO Actors (
FirstName, SecondName, DoB, Gender, MaritalStatus, NetworthInMillions)
VALUES ("Brad", "Pitt", "1963-12-18", "Male", "Single", 240.00);
-- Query 2
INSERT INTO Actors (
FirstName, SecondName, DoB, Gender, MaritalStatus, NetworthInMillions)
VALUES
("Jennifer", "Aniston", "1969-11-02", "Female", "Single", 240.00),
("Angelina", "Jolie", "1975-06-04", "Female", "Single", 100.00),
("Johnny", "Depp", "1963-06-09", "Male", "Single", 200.00);
-- Query 3
INSERT INTO Actors
VALUES (DEFAULT, "Dream", "Actress", "9999-01-01", "Female", "Single", 000.00);
-- Query 4
INSERT INTO Actors VALUES (NULL, "Reclusive", "Actor", "1980-01-01", "Male", "Single", DEFAULT);
-- Query 5
INSERT INTO Actors () VALUES ();
-- Query 6
INSERT INTO Actors SET DoB="1950-12-12", FirstName="Rajnikanth", SecondName="", Gender="Male", NetWorthInMillions=50, MaritalStatus="Married";
Terminal 1
Terminal
Loading...
  1. Now we’ll add a row to our, so far empty, Actors table using the INSERT command. Copy and paste the following ...

Access this course and 1400+ top-rated courses and projects.