SQLite 仅仅支持 ALTER TABLE 语句的一部分功能,我们可以用 ALTER TABLE 语句来更改一个表的名字,也可向表中增加一个字段(列),但是我们不能删除一个已经存在的字段,或者更改一个已经存在的字段的名称、数据类型、限定符等等。
改变表名 - ALTER TABLE 旧表名 RENAME TO 新表名
增加一列 - ALTER TABLE 表名 ADD COLUMN 列名 数据类型
- SELECT name FROM sqlite_master where type='table' order by name;
-
1,导出数据库某个表:
- # 先执行
- .output table_name.sql
- # 在执行
- .dump table_name
-
如果是导出全部表:
直接 .dump
2,导入数据表:
- .read table_name.sql
-
1,导出表:
- cmd = "sqlite3 db.sqlite3 '.dump table_name' > table_name.sql"
- os.system(cmd)
-
2,导入表:
- cmd = "sqlite3 db.sqlite3 '.read table_name.sql' "
- os.system(cmd)
-
- 执行“sqlite3.exe”,我们可能用到下面几个命令:
- sqlite> .help
- .dump ?TABLE? ... Dump the database in an SQL text format
- If TABLE specified, only dump tables matching
- LIKE pattern TABLE.
- .exit Exit this program
- .help Show this message
- .open ?--new? ?FILE? Close existing database and reopen FILE
- The --new starts with an empty file
- .output ?FILENAME? Send output to FILENAME or stdout
- .quit Exit this program
- .read FILENAME Execute SQL in FILENAME
- .tables ?TABLE? List names of tables
- If TABLE specified, only list tables matching
- LIKE pattern TABLE.
- sqlite>
-
- sqlite3 -csv -header vz3.db "select * from t_city_domestic_all_new" > city.csv
-