1.打开或创建数据库,在命令行中输入sqlite3 ***(***是你的数据库名)
2.创建三个表如:
CREATE TABLE "main"."Product"
(
"ID" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"Name" TEXT,
"ManufacturerID" INTEGER,
"Details" TEXT,
"Price" DOUBLE,
"QuantityOnHand" INTEGER,
"CoutryOfOriginID" INTEGER,
"IMAGE" TEXT
);
CREATE TABLE "main"."Country"
(
"CountryID" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"Country" TEXT NOT NULL
);
CREATE TABLE "main"."Manufacturer"
(
"ManufacturerID" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"Name" TEXT NOT NULL
);
3.批量导入数据
3.1 建一个Porducts.txt文本文件,用制表符作为字段间的分隔符
1 Widget A 1 Details of widget A 1.29 5 1 Canvas_1
2 Widget B 1 Details of Widget B 4.29 15 2 Canvas_2
3 Widget X 2 Details of Widget X 0.29 25 3 Canvas_3
3.2 给Product表导入数据
如果还没打开sqlte命令提示符,则先打开它,输入命令.separator "\t",指定制表符\t作为数据文件中字段的分隔符
接着输入.import "Product.txt" Product,即导入Product.txt 文件到Product表中
4. 建一个Conutry.txt 和Manufacturet.txt 导入方法同3
Country.txt
1 USA
2 Taiwam
3 China
Manufacturet.txt
1Spirit Industries 2Industrial Design 3Design Intl 4Tool Masters