1.37. SQLite Alter command

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

SQLite’s ALTER TABLE The command does not modify an existing table by performing a complete dump and reloading of the data. You can use the ALTER TABLE Statement to rename the table, using the ALTER TABLE Statement can also add additional columns to an existing table.

In SQLite Except for renaming tables and adding columns to existing tables, the ALTER TABLE command does not support other operations.

1.37.1. Grammar

Used to rename an existing table ALTER TABLE The basic syntax is as follows:

ALTER TABLE database_name.table_name RENAME TO new_table_name;

Used to add a new column to an existing table ALTER TABLE The basic syntax is as follows:

ALTER TABLE database_name.table_name ADD COLUMN column_def...;

1.37.2. Example

Suppose our COMPANY The table has the following records:

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

Now, let’s try using the ALTER TABLE Statement to rename the table as follows:

sqlite> ALTER TABLE COMPANY RENAME TO OLD_COMPANY;

Above. SQLite Statement will be renamed COMPANY The table is OLD_COMPANY . Now, let’s try to OLD_COMPANY Add a new column to the table, as follows:

sqlite> ALTER TABLE OLD_COMPANY ADD COLUMN SEX char(1);

Now, the COMPANY table has changed, using the SELECT The statement output is as follows:

ID          NAME        AGE         ADDRESS     SALARY      SEX
----------  ----------  ----------  ----------  ----------  ---
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

Note that the newly added columns are as follows NULL Value to fill in.

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.