SQLite 基础6

2021-12-01 17:16:27 浏览数 (2)

创建表

代码语言:javascript复制
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 是不能接 ; 的,而增删改查类操作是必须要以 ; 结尾的

代码语言:javascript复制
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> 

0 人点赞