//摘自:http://anony3721.blog.163.com/blog/static/51197420107552520990/
sqlite 执行sql文件
sqlite是支持导入sql文件的,只要使用内置命令.read 即可。以下sql文件,命名为foo.sql
create table Artists (
ArtistID INTEGER PRIMARY KEY ,
ArtistName TEXT );
create table CDs (
CDID INTEGER PRIMARY KEY ,
ArtistID INTEGER NOT NULL ,
Title TEXT NOT NULL ,
Date TEXT );
insert into Artists (ArtistID,ArtistName) values ( NULL , ' Peter Gabriel ' );
insert into Artists (ArtistID,ArtistName) values ( NULL , ' Bruce Hornsby ' );
insert into Artists (ArtistID,ArtistName) values ( NULL , ' Lyle Lovett ' );
insert into Artists (ArtistID,ArtistName) values ( NULL , ' Beach Boys ' );
insert into CDs (CDID,ArtistID,Title,Date) values ( NULL , 1 , ' So ' , ' 1984 ' );
insert into CDs (CDID,ArtistID,Title,Date) values ( NULL , 1 , ' Us ' , ' 1992 ' );
insert into CDs (CDID,ArtistID,Title,Date) values ( NULL , 2 , ' The Way It Is ' , ' 1986 ' );
insert into CDs (CDID,ArtistID,Title,Date) values ( NULL , 2 , ' Scenes from the Southside ' , ' 1990 ' );
insert into CDs (CDID,ArtistID,Title,Date) values ( NULL , 1 , ' Security ' , ' 1990 ' );
insert into CDs (CDID,ArtistID,Title,Date) values ( NULL , 3 , ' Joshua Judges Ruth ' , ' 1992 ' );
insert into CDs (CDID,ArtistID,Title,Date) values ( NULL , 4 , ' Pet Sounds ' , ' 1966 ' );
接着在命令行里运行
sqlite>.read foo.sql