Course

Inserting Data

What good is a database without data?

Let's talk about inserting rows into our 'Users' table. In a web application, we would be performing this action whenever we register a new user. "Inserting" means 'Creating A New Entry':

When we INSERT a new row, we only need to provide the values that don't have a default, and we won't need to provide an ID (as the ID is set to 'auto_increment')

ID (INT)name (VARCHAR)email (VARCHAR) (UNIQUE)createdAt (TIMESTAMP)updatedAt (TIMESTAMP)
1Amiramir@email.com2024-04-17 21:10:522024-04-17 21:10:52
2Jackiejackie@email.com2024-04-17 21:10:522024-04-17 21:10:52
INSERT INTO Users (name, email)
VALUES ("Oscar","oscar@email.com");
ID (INT)name (VARCHAR)email (VARCHAR) (UNIQUE)createdAt (TIMESTAMP)updatedAt (TIMESTAMP)
Oscaroscar@email.com
ID (INT)name (VARCHAR)email (VARCHAR) (UNIQUE)createdAt (TIMESTAMP)updatedAt (TIMESTAMP)
1Amiramir@email.com2024-04-17 21:10:522024-04-17 21:10:52
2Jackiejackie@email.com2024-04-17 21:10:522024-04-17 21:10:52
3Oscaroscar@email.com2024-04-17 22:10:522024-04-17 22:10:52

Here we've "Inserted" a new row into the "Users" table with a name and an email.

Our Database automatically populates all the default fields.

Let's take a look at the statement.

INSERT INTO Users (name, email)
VALUES ("Oscar","oscar@email.com");

The Insert statment has 3 unique parts. We need:

  • The Table name we're inserting into
  • The fields we're going to insert
  • The values we're be inserting into those fields

0 Comments

"Please login to view comments"

glass-bbok

Join the Conversation!

Subscribing gives you access to the comments so you can share your ideas, ask questions, and connect with others.

Upgrade your account
tick-guideNext Lesson

Multiple Inserts