Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Inserting Rows into a Table | Populating a Database
Introduction to SQL

bookInserting Rows into a Table

After creating a table, we can insert rows into it using an INSERT statement.

Following is the general syntax of an INSERT statement:

INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

In the above syntax, the table_name refers to the name of the table in which we want to insert a row.

The sequence of values (value1, value2, value3, ...) needs to be in the same order as the sequence of the columns that are specified at (column1, column2, column3, ...).

For example:

INSERT INTO students (first_name, second_name, age) VALUES ('John', 'Doe', 24);

// OR

INSERT INTO students (second_name, first_name, age) VALUES ('Doe', 'John', 24);

// OR

INSERT INTO students (age, first_name, second_name) VALUES (24, 'John', 'Doe');

// etc

Demonstration:

Tip:

There is a shorter syntax for inserting rows into a table:

INSERT INTO table_name VALUES (value1, value2, value3 …)

For example:

INSERT INTO students VALUES ('John', 'Doe', 24);

In this case, the order in which the values are stated should be the same as the default order of the columns.

The difference between the use cases of the two syntaxes we explored will become more apparent in the later chapters.

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 3

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Ask me questions about this topic

Summarize this chapter

Show real-world examples

Awesome!

Completion rate improved to 1.72

bookInserting Rows into a Table

Swipe to show menu

After creating a table, we can insert rows into it using an INSERT statement.

Following is the general syntax of an INSERT statement:

INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

In the above syntax, the table_name refers to the name of the table in which we want to insert a row.

The sequence of values (value1, value2, value3, ...) needs to be in the same order as the sequence of the columns that are specified at (column1, column2, column3, ...).

For example:

INSERT INTO students (first_name, second_name, age) VALUES ('John', 'Doe', 24);

// OR

INSERT INTO students (second_name, first_name, age) VALUES ('Doe', 'John', 24);

// OR

INSERT INTO students (age, first_name, second_name) VALUES (24, 'John', 'Doe');

// etc

Demonstration:

Tip:

There is a shorter syntax for inserting rows into a table:

INSERT INTO table_name VALUES (value1, value2, value3 …)

For example:

INSERT INTO students VALUES ('John', 'Doe', 24);

In this case, the order in which the values are stated should be the same as the default order of the columns.

The difference between the use cases of the two syntaxes we explored will become more apparent in the later chapters.

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 3
some-alt