1.10. SQLite create table

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

Page Views: 10 views

SQLite’s CREATE TABLE Statement is used to create a new table in any given database. Creating a basic table involves naming the table, defining the column, and the data type of each column.

1.10.1. Grammar

The basic syntax of the CREATE TABLE statement is as follows:

CREATE TABLE database_name.table_name( column1 datatype PRIMARY KEY(one or more columns), column2 datatype, column3 datatype, ..... columnN datatype, ); 

CREATE TABLE is the keyword that tells the database system to create a new table. The CREATE TABLE statement is followed by the unique name or identity of the table. You can also choose to specify with table_name Of database_name .

1.10.2. Example

The following is an example that creates a COMPANY table with ID as the primary key, and the constraint of NOT NULL means that these fields cannot be NULL when creating records in the table:

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

Let’s create another table, which we will use in the exercises in subsequent chapters:

sqlite> CREATE TABLE DEPARTMENT( ID INT PRIMARY KEY NOT NULL, DEPT CHAR(50) NOT NULL, EMP_ID INT NOT NULL ); 

You can use the .tables Command to verify that the table has been created successfully, which is used to list all tables in the attached database.

sqlite>.tables COMPANY DEPARTMENT 

Here, you can see the two tables we just created, COMPANY and DEPARTMENT.

You can use SQLite .schema Command to get the complete information about the table, as follows:

sqlite>.schema COMPANY CREATE TABLE COMPANY( ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL ); 
《地理信息系统原理、技术与方法》  97

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