/

How to Insert Data into a SQL Database Table

How to Insert Data into a SQL Database Table

Adding data to a table in a SQL database is a common task in database management. In this article, we will explore the process of inserting data into a SQL table.

To illustrate the process, let’s consider a sample table called “people” with two columns: “age” (of type INT) and “name” (of type CHAR(20)).

1
2
3
4
CREATE TABLE people (
age INT,
name CHAR(20)
);

Once the table is created, you can start populating it with data using the INSERT INTO command. The INSERT INTO statement allows you to specify the table name and provide values for each column in the table.

For example, to add a single row of data to the “people” table, you can use the following syntax:

1
INSERT INTO people VALUES (37, 'Flavio');

Here, we inserted a row with an age of 37 and a name of ‘Flavio’.

If you want to insert multiple rows at once, you can separate each row with a comma. For instance:

1
INSERT INTO people VALUES (37, 'Flavio'), (8, 'Roger');

This statement adds two rows simultaneously, one with an age of 37 and a name of ‘Flavio’, and another with an age of 8 and a name of ‘Roger’.

By following these steps, you can easily add data to a SQL table using the INSERT INTO command. It’s an efficient way to populate your database and make it ready for use.

Tags: SQL, database management, INSERT INTO, data insertion