sqlite 执行sql文件

//摘自: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 

    原文作者:sqlite
    原文地址: https://www.cnblogs.com/xunxun/archive/2011/03/03/1969715.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞