在SQLite数据库中插入数据的代码如下:
- myqiao@ubuntu:~/My Documents/db$ sqlite3 test.db
- -- Loading resources from /home/myqiao/.sqliterc
- SQLite version 3.7.4
- Enter ".help" for instructions
- Enter SQL statements terminated with a ";"
- sqlite> .tables
- sqlite>
- sqlite> CREATE TABLE Teachers(
- sqlite> Id integer PRIMARY KEY,
- sqlite> Name text NOT NULL,
- sqlite> Age integer CHECK(Age>22),
- sqlite> Country text DEFAULT 'USA');
- sqlite> .tables
- Teachers
- sqlite>
- sqlite> INSERT INTO Teachers VALUES(1,'Alice',25,'CHN');
- sqlite> INSERT INTO Teachers VALUES(2,'Bob',25,'BRA');
- sqlite> INSERT INTO Teachers(Id,Name,Age,Country) VALUES(3,'Charls',33,'USA');
- sqlite> INSERT INTO Teachers(Name,Age) VALUES('Jhon',43);
- sqlite> SELECT * FROM Teachers;
- Id Name Age Country
- ---- --------------- --------------- ---------------
- 1 Alice 25 CHN
- 2 Bob 25 BRA
- 3 Charls 33 USA
- 4 Jhon 43 USA
- sqlite>
上面的代码很简单,创建了一个 Teachers 表并向其中添加了四条数据,设定了一些约束,其中有自动增加的主键、默认值等等。
关于SQLite数据库插入数据的知识就介绍到这里,谢谢各位的支持!
【编辑推荐】