接下来,将用一个详细的例子完成学习(建议学习者着重事先看下关系模型):@H_404_1@
主表是foods表,@H_404_1@
@H_404_1@
@H_404_1@
创建临时表的时候,语法是:create temp/temporary table table_name( column_definitions [,constraints ] ) ; @H_404_1@
@H_404_1@
接下来,输入的echo on、mode column、 header on、nullvalue NUll,表示:将在屏幕上打印sql语句,以列表的形式显示表格,包含列名称,将nulls打印成NULL.。@H_404_1@
在和sqlite3.exe相同的路径下建立test . txt文件,输入:@H_404_1@
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);
@H_404_1@
然后在命令提示符框中进行如下操作(在命令提示框中键入.read test.txt):@H_404_1@
@H_404_1@
然后新建文件select . txt ,输入:@H_404_1@
select * from foods_episode;
select * from episodes;
select * from food_tyes;
select * from foods;
@H_404_1@
@H_404_1@
其他的因为面积太大,就不发了。反正基本上一致,结果显示正确。也可以看见,id字段是自动增长的。@H_404_1@
接下来:@H_404_1@
select@H_404_1@
注意的几点:字符常量尽量有单引号,关键字和标示符不区分大小写,但是字符常量的大小写是不一样的;注释用——连续连字符,c语言风格的注释一般是不允许的;sqlite在修改表的过程中,alter table 命令是有局限性的。@H_404_1@