https://www.sqlite.org/2021/sqlite-tools-win32-x86-3360000.zip
解压缩后 3 个文件
sqldiff.exe 数据库比较工具
sqlite3.exe 数据库命令行交互工具
sqlite3_analyzer.exe 数据库分析器
Sqlite 数据库命令行的启动与帮助信息的获取
用 DOS 进入解压缩后的文件夹,并运行命令 sqlite3.exe,进入其命令行 shell.
sqltie>.help
利用 Sqlite 数据库命令行创建数据库
sqlite>.open TestDB /打开并创建一个名为 TestDB 的数据库文件,若没有此文件就创建/
sqlite>CREATE TABLE websites (
id int Not Null Primary Key,
name varchar(20) Not Null,
url varchar(255) Not Null,
alexa int(11) Not Null,
country char(20) Not Null
);
sqlite>INSERT INTO websites VALUES
('1', 'Google', 'https://www.google.cm/', '1', 'USA'),
('2', '淘宝', 'https://www.taobao.com/', '13', 'CN'),
('3', '菜鸟教程', 'http://www.runoob.com', '5892', ''),
('4', '微博', 'http://weibo.com/', '20', 'CN'),
('5', 'Facebook', 'https://www.facebook.com/', '3', 'USA');
sqlite>.quit.
sqlite> .open exp8.db
sqlite> create table Studs(
...> id int not null primary key,
...> name varchar(20) not null
...> );
sqlite> select *from Studs
...> ;
sqlite> create table Teachers(
...> id int not null primary key,
...> name varchar(20) not null
...> );
sqlite> create table Courses(
...> id int not null primary key,
...> name varchar(20) not null
...> );
sqlite> create table selectCourses(
...> id integer primary key autoincrement,
...> curdate date default now,
...> stid char(8),
...> coid char(8),
...> constraint fk_1 foreign Key(stid) references Studs(id),
...> constraint fk_2 foreign Key(coid) references Coursee(id)
...> );
sqlite> create table teachings(
...> id integer primary key autoincrement,
...> curdate date default now,
...> coid char(8),
...> teid char(8),
...> constraint fk_1 foreign Key(coid) references Courses(id),
...> constraint fk_2 foreign Key(teid) references Teachers(id)
...> );
注意:在学生表和课程表之间的“业务表”。必须包含三个属性:
1.业务发生的时间。
2.是谁进行的该业务的操作。
3.业务发生的唯一Id
sqlite> insert into Studs values
...> ('2012151','王明'),
...> ('2012152','张旭'),
...> ('2012153','刘琦');
sqlite> select * from Studs
...> ;
2012151|王明
2012152|张旭
2012153|刘琦
sqlite> insert into Courses values
...> ('1','JavaEE'),
...> ('2','数据库'),
...> ('3','C语言');
sqlite> insert into Teachers values
...> ('1','王玉'),
...> ('2','张宇'),
...> ('3','刘洋');
drop table +表名