SQL INSERT INTO TABLE Tutorial W3Schools Guide básicos de inserción de datos

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!

Create Tables in SQL Server with T-SQL
Create Tables in SQL Server with T-SQL

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'.

SQL INSERT Statement | How to Insert Data in SQL Tables
SQL INSERT Statement | How to Insert Data in SQL Tables

Understanding the INSERT INTO Statement

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

7 ways to insert data into Sql Server table
7 ways to insert data into Sql Server table

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

Inserting Single Row

SQL Server Create table command
SQL Server Create table command

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.

Learn SQL Fast 🚀 | Beginner SQL Commands Cheat Sheet for Data Analysts
Learn SQL Fast 🚀 | Beginner SQL Commands Cheat Sheet for Data Analysts

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)

SQL Cheat Sheet in 60 seconds 👇
SQL Cheat Sheet in 60 seconds 👇

In this example, we've inserted two new students into the 'students' table. Easy, right?

Inserting Data with NULL Values

SQL Joins Cheat Sheet Every Developer Should Save
SQL Joins Cheat Sheet Every Developer Should Save
SQL Table Queries | Create, Select, Insert & Update Tables
SQL Table Queries | Create, Select, Insert & Update Tables
a table that has some words on it
a table that has some words on it
an image of a table with numbers and tables for each piece in the game, which is
an image of a table with numbers and tables for each piece in the game, which is
Sql Cheat Sheet, Learn Sql, Learn Web Development, Excel Tutorials, Sql Server, Career Options, Data Analyst, Data Scientist, Data Analysis
Sql Cheat Sheet, Learn Sql, Learn Web Development, Excel Tutorials, Sql Server, Career Options, Data Analyst, Data Scientist, Data Analysis
SQL Basics Tutorial for Beginners – Structured Query Language Commands, Syntax & Examples Guide
SQL Basics Tutorial for Beginners – Structured Query Language Commands, Syntax & Examples Guide
How To Insert Results From Stored Procedure To A Temp Table In SQL Server?
How To Insert Results From Stored Procedure To A Temp Table In SQL Server?
SQL in 60 days
SQL in 60 days
a table with different types of text on it
a table with different types of text on it
SQL Basics Cheat Sheet for Beginners | Learn SQL Fast 💻
SQL Basics Cheat Sheet for Beginners | Learn SQL Fast 💻
SQL - Find salesman commission details of given customer
SQL - Find salesman commission details of given customer
an image of a table with the names and numbers for different types of data sources
an image of a table with the names and numbers for different types of data sources
2.4K views · 102 reactions | 🎯 SQL Cheatsheet – Everything You Need at a Glance Master SQL fundamentals with this clean and powerful SQL Cheatsheet 🚀 Perfect for beginners, developers, data analysts, and inte | Codewithprashantt
2.4K views · 102 reactions | 🎯 SQL Cheatsheet – Everything You Need at a Glance Master SQL fundamentals with this clean and powerful SQL Cheatsheet 🚀 Perfect for beginners, developers, data analysts, and inte | Codewithprashantt
SQL Joins Explained with Examples | Complete JOIN Cheat Sheet for Beginners
SQL Joins Explained with Examples | Complete JOIN Cheat Sheet for Beginners
SQL Query Execution Order
SQL Query Execution Order
SQL - Select all columns that satisfy a specific condition
SQL - Select all columns that satisfy a specific condition
Creating Databases | MySQL for Beginners
Creating Databases | MySQL for Beginners
Insert Data into MySQL Table
Insert Data into MySQL Table
SQL Cheatsheet In 2026 🚀
SQL Cheatsheet In 2026 🚀
a sheet of paper that has some notes on it with words and symbols in the middle
a sheet of paper that has some notes on it with words and symbols in the middle

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!

Related Articles

Sql Where Count 3 W3school Sql Practice W3 Resources Database Sql Server Declare Date Sql3 Create Table What Is Sql Training Sql Concat Example W3 Alter Table W3 School Sql Reddit W3school Sql Server