学习使用SQLite(版本3.7.4)(中A)

前端之家收集整理的这篇文章主要介绍了学习使用SQLite(版本3.7.4)(中A)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

接下来,将用一个详细的例子完成学习(建议学习者着重事先看下关系模型):

主表是foods表,



创建临时表的时候,语法是:create temp/temporary table table_name( column_definitions [,constraints ] ) ;


接下来,输入的echo on、mode column、 header on、nullvalue NUll,表示:将在屏幕上打印sql语句,以列表的形式显示表格,包含列名称,将nulls打印成NULL.。

在和sqlite3.exe相同的路径下建立test . txt文件,输入:



INSERT INTO episodes (season,name)VALUES (1,'xifan ');
INSERT INTO episodes (season,name)VALUES (2,'momo ');
INSERT INTO episodes (season,name)VALUES (3,'jituitui ');
INSERT INTO episodes (season,name)VALUES (4,'jibangbang');
INSERT INTO episodes (season,'jizhuazhua');
INSERT INTO episodes (season,"jiguanzi ");




--insert into food_types(id,name) values ( )
INSERT INTO food_types(id,'jizhuazhua');
INSERT INTO food_types(id,'xifan ');
INSERT INTO food_types(id,'momo ');
INSERT INTO food_types(id,'jituitui ');
INSERT INTO food_types(id,name)VALUES (5,'jibangbang');
INSERT INTO food_types(id,name)VALUES (6,'jiguanzi ');


--insert into foods(id,type_id,name)values()
INSERT INTO foods(type_id,'jizhuazhua');
INSERT INTO foods(type_id,'xifan ');
INSERT INTO foods(type_id,'momo ');
INSERT INTO foods(type_id,'jituitui ');
INSERT INTO foods(type_id,'jibangbang');
INSERT INTO foods(type_id,'jiguanzi ');


--insert into food_episodes(food_id,episodes_id)values()
INSERT INTO foods_episode(food_id,episode_id)VALUES ( 1,1);
INSERT INTO foods_episode(food_id,episode_id)VALUES ( 2,2);
INSERT INTO foods_episode(food_id,episode_id)VALUES ( 3,3);
INSERT INTO foods_episode(food_id,episode_id)VALUES ( 4,4);
INSERT INTO foods_episode(food_id,episode_id)VALUES ( 5,5);
INSERT INTO foods_episode(food_id,episode_id)VALUES ( 6,6);

然后在命令提示符框中进行如下操作(在命令提示框中键入.read test.txt):


然后新建文件select . txt ,输入:

select * from foods_episode;
select * from episodes;
select * from food_tyes;
select * from foods;


其他的因为面积太大,就不发了。反正基本上一致,结果显示正确。也可以看见,id字段是自动增长的。

接下来:

select

修改

增加一列:

修改表名:

注意的几点:字符常量尽量有单引号,关键字和标示符不区分大小写,但是字符常量的大小写是不一样的;注释用——连续连字符,c语言风格的注释一般是不允许的;sqlite在修改表的过程中,alter table 命令是有局限性的。

原文链接:https://www.f2er.com/sqlite/201815.html

猜你在找的Sqlite相关文章