Are you new to SQL and looking to insert data into a table? You've come to the right place! In this guide, we'll walk you through the process in simple, easy-to-understand steps, using practical examples inspired by W3Schools. Let's dive in!

Before we start, ensure you have a basic understanding of SQL. If not, W3Schools offers a comprehensive SQL tutorial that can help you build a solid foundation. Now, let's assume we have a database named 'school' and we want to insert data into a table called 'students'.

Understanding the INSERT INTO Statement
The 'INSERT INTO' statement is used to insert new data into a table. It follows this basic syntax:

INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...)
Inserting Single Row

To insert a single row into the 'students' table, you would use the following SQL query:
INSERT INTO students (firstName, lastName, age) VALUES ('John', 'Doe', 20)
Here, we're inserting a new student with the first name 'John', last name 'Doe', and age 20 into the 'students' table.

Inserting Multiple Rows
You can also insert multiple rows at once. To do this, simply list the values in parentheses like so:
INSERT INTO students (firstName, lastName, age) VALUES ('Jane', 'Doe', 19), ('Jim', 'Smith', 22)

In this example, we've inserted two new students into the 'students' table. Easy, right?
Inserting Data with NULL Values




















When inserting data, you can also use NULL to represent a missing or unknown value. Here's how you can do it:
Using NULL Values
Let's assume the 'students' table has a 'GPA' column, and we don't have John's GPA yet. We can insert his data with a NULL value for GPA like this:
INSERT INTO students (firstName, lastName, age, GPA) VALUES ('John', 'Doe', 20, NULL)
In this query, we're telling SQL to leave the 'GPA' field empty for John.
Inserting NULL into Specific Column
You can also insert NULL into a specific column for all rows. Let's assume we want to insert multiple students with no GPA yet:
INSERT INTO students (firstName, lastName, age) VALUES ('John', 'Doe', 20), ('Jane', 'Doe', 19); INSERT INTO students (GPA) VALUES (NULL);
Here, we first insert the students without a GPA. Then, we update the GPA column for all the rows we just inserted with NULL values.
And there you have it! You now know how to insert data into a table using the 'INSERT INTO' statement in SQL. Practice these concepts using W3Schools' SQL editor or your preferred SQL environment. Happy coding!