1.37. SQLite Alter command

发布时间 : 2025-10-25 13:32:45 UTC      

Page Views: 9 views

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.

《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。