1.12. SQLite Insert statement

发布时间 :2025-10-25 12:23:15 UTC      

SQLite’s INSERT INTO Statement is used to add a new data row to a table in the database.

1.12.1. Grammar

There are two basic syntaxes for INSERT INTO statements, as follows:

INSERT INTO TABLE_NAME [(column1, column2, column3,...columnN)]
VALUES (value1, value2, value3,...valueN);

Here, column1, column2,…columnN is the name of the column in the table where the data is to be inserted.

If you want to add values to all columns in the table, you may not need to specify column names in the SQLite query. However, make sure that the order of the values is the same as the order of the columns in the table. The INSERT INTO syntax for SQLite is as follows:

INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);

1.12.2. Example

Suppose you are already in the testDB.db The COMPANY table is created in, as follows:

sqlite> CREATE TABLE COMPANY(
   ID INT PRIMARY KEY     NOT NULL,
   NAME           TEXT    NOT NULL,
   AGE            INT     NOT NULL,
   ADDRESS        CHAR(50),
   SALARY         REAL
);

Now, the following statement will be used in the COMPANY Create six records in the table:

INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (1, 'Paul', 32, 'California', 20000.00 );

INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (2, 'Allen', 25, 'Texas', 15000.00 );

INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (3, 'Teddy', 23, 'Norway', 20000.00 );

INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );

INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (5, 'David', 27, 'Texas', 85000.00 );

INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (6, 'Kim', 22, 'South-Hall', 45000.00 );

You can also use the second syntax in the COMPANY Create a record in the table as follows:

INSERT INTO COMPANY VALUES (7, 'James', 24, 'Houston', 10000.00 );

All of the above statements will be in the COMPANY Create the following records in the table. The next chapter will teach you how to display all of these records from one table.

ID          NAME        AGE         ADDRESS     SALARY
----------  ----------  ----------  ----------  ----------
1           Paul        32          California  20000.0
2           Allen       25          Texas       15000.0
3           Teddy       23          Norway      20000.0
4           Mark        25          Rich-Mond   65000.0
5           David       27          Texas       85000.0
6           Kim         22          South-Hall  45000.0
7           James       24          Houston     10000.0

1.12.3. Use one table to populate another table

You can use the select Statement to populate the data into another table. Here is the syntax:

INSERT INTO first_table_name [(column1, column2, ... columnN)]
   SELECT column1, column2, ...columnN
   FROM second_table_name
   [WHERE condition];

For the time being, you can skip the above statement and learn what is described in later chapters. SELECT And WHERE Clause.

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.