zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

SQLite 基础6

2023-03-20 15:36:30 时间

创建表

sqlite> create table test ( id int primary key not null, name text );
sqlite> .tables
test
sqlite> .schema test
CREATE TABLE test ( id int primary key not null, name text );
sqlite> 
sqlite> insert into test values(1,"hello");
sqlite> insert into test values(2,"hello");         
sqlite> insert into test values(3,"hello");
sqlite> select * from test;
1|hello
2|hello
3|hello
sqlite> 

Tip: 以点开头的管理命令,如 .tables.schema 是不能接 ; 的,而增删改查类操作是必须要以 ; 结尾的

sqlite> .table
test
sqlite> .table;
Error: unknown command or invalid arguments:  "table;". Enter ".help" for help
sqlite> insert into test values(4,"hello");
sqlite> insert into test values(5,"hello")
   ...> 
   ...> 
   ...> 
   ...> 
   ...> 
   ...> 
   ...> 
   ...> ;
sqlite> insert into test values(5,"hello")
   ...> 
   ...> 
   ...> 
   ...> 
   ...> 
   ...> 
   ...> ;
Error: UNIQUE constraint failed: test.id
sqlite>