简单记录一下,后来有更改但是也没有更新了,所以可能有很多小错误…
(1) 管理员tb_Admin
属性 | 说明 | 数据类型 | 约束 |
---|---|---|---|
AdminID | 工号 | int | 主键,自增字段 |
AdminName | 用户名 | varchar(20) | not null,unique |
AdminPwd | 密码 | varchar(64) | not null |
AdminTruename | 真实姓名 | varchar(20) | not null |
AdminSex | 性别 | varchar(2) | not null,取男/女 |
AdminAge | 年龄 | int | not null,大于0且不超过120 |
AdminFlag | 标签 | int | not null,取0/1,0为普通管理员,1为超级管理员 |
create table tb_Admin(
AdminID int auto_increment,
AdminName varchar(20) not null,
AdminPwd varchar(20) not null,
AdminTruename varchar(20) not null,
AdminSex varchar(2) not null,
AdminAge int not null,
primary key(AdminID),
check(AdminSex in ('男','女')),
check(AdminAge > 0 and AdminAge < 120))
(2)书籍信息tb_Book
属性 | 说明 | 数据类型 | 约束 |
---|---|---|---|
BookID | 图书编号 | int | 主键,自增字段 |
Bookisbn | 图书ISBN | varchar(20) | not null,unique |
BookName | 图书名称 | varchar(20) | not null |
BookPress | 出版社 | varchar(20) | not null |
BookPubDate | 出版日期 | varchar(20) | not null |
BookAuthor | 作者 | varchar(10) | not null |
BookInPrice | 进货价格 | real | not null,大于0 |
create table tb_Book(
BookID INTEGER PRIMARY KEY AUTOINCREMENT,
Bookisbn varchar(20) not null,
BookName varchar(20) not null,
BookPress varchar(20) not null,
BookPubDate varchar(20) not null,
BookAuthor varchar(10) not null,
BookInPrice REAL not null,
check(BookInPrice > 0 ))
(3)库存书籍tb_Storage
属性 | 说明 | 数据类型 | 约束 |
---|---|---|---|
BookID | 图书编号 | int | 主键,引用tb_Book的外键级联删除、更新 |
BookStoreMount | 库存量 | int | not null,大于0 |
BookStoretime | 入库时间 | date | not null |
BookMPrice | 售价 | real | not null,大于0 |
create table tb_Storage(
BookID int,
BookStoreMount int not null,
BookStoretime date not null,
primary key(BookID),
foreign key (BookID) references tb_Book
on delete cascade
on update cascade,
check (BookStoreMount > 0))
(4)买家购物车tb_Shopbasket
属性 | 说明 | 数据类型 | 约束 |
---|---|---|---|
ShopID | 订单编号 | int | 主码,引用tb_SOrder的外键,级联删除更新 |
BookID | 图书ID | int | 主码,引用tb_Book的外键,级联删除更新 |
ShopMount | 图书数量 | int | not null大于0 |
ShopPrice | 图书单价 | money | not null大于0 |
create table tb_Shopbasket(
ShopID int,
BookID int,
ShopMount int not null,
ShopPrice money not null,
primary key (ShopID,BookID),
foreign key (ShopID) references tb_SOrder
on delete cascade
on update cascade,
foreign Key (BookID) references tb_Book
on delete cascade
on update cascade,
check(ShopMount > 0 ),
check(ShopPrice > 0 ))
(5)买家订单tb_SOrder
属性 | 说明 | 数据类型 | 约束 |
---|---|---|---|
ShopID | 订单编号 | int | 主码,自增 |
ShopSum | 总价 | money | not null,大于0 |
ShopState | 订单状态 | varchar(10) | 默认未付款,取“已付款”/“未付款” |
create table tb_SOrder(
ShopID int auto_increment,
ShopSum money not null,
ShopState varchar(20) default'未付款' not null,
primary key (ShopID),
check (ShopSum > 0),
check (ShopState in ('已付款','未付款')))
(6)进货购物车tb_Inputbasket
属性 | 说明 | 数据类型 | 约束 |
---|---|---|---|
InputID | 订单编号 | int | 主码,引用tb_InOrder的外键,级联删除、更新 |
BookID | 图书编号 | int | 主码,引用tb Book的外键,级联删除、更新 |
InputPrice | 进货单价 | real | not null,大于0 |
InputMount | 进货数量 | int | not null,大于0 |
create table tb_Inputbasket(
InputID int,
BookID int,
InputPrice money not null,
InputMount int not null,
primary key(InputID,BookID),
foreign key(InputID) references tb_InOrder
on delete cascade
on update cascade,
foreign key(BookID) references tb_Book
on delete cascade
on update cascade,
check(InputPrice > 0),
check(InputMount > 0))
(7)进货订单tb_InOrder
属性 | 说明 | 数据类型 | 约束 |
---|---|---|---|
InputID | 订单编号 | int | 主码,自增字段 |
InputSum | 总价 | real | not null,大于0 |
InputState | 订单状态 | varchar(10) | 默认未付款,取“已付款”或者“未付款”/“已退货”/“订单完成” |
create table tb_InOrder(
InputID int auto_increment,
InputSum money not null,
InputState varchar(10) default'未付款' not null,
primary key(InputID),
check (InputSum > 0),
check (InputState in ('已付款','未付款')))
(8) 账单信息tb_Order
属性 | 说明 | 数据类型 | 约束 |
---|---|---|---|
OrderID | 账单编号 | int | 主码,自增字段 |
OrderTime | 操作时间 | varchar(20) | not null |
OrderType | 收支类型 | varchar(5) | 取+/— |
OrderTotal | 数额 | real | not null,大于0 |
create table tb_Order(
OrderID int auto_increment,
OrderTime timestamp not null,
OrderType varchar(5) not null,
OrderTotal money not null,
primary key(OrderID),
check(OrderType in ('+','-')),
check(OrderTotal > 0))
总体代码:
create table tb_Admin(
AdminID int auto_increment,
AdminName varchar(20) not null,
AdminPwd varchar(20) not null,
AdminTruename varchar(20) not null,
AdminSex varchar(2) not null,
AdminAge int not null,
primary key(AdminID),
check(AdminSex in ('男','女')),
check(AdminAge > 0 and AdminAge < 120))
create table tb_Book(
BookID INTEGER PRIMARY KEY AUTOINCREMENT,
Bookisbn varchar(20) not null,
BookName varchar(20) not null,
BookPress varchar(20) not null,
BookPubDate varchar(20) not null,
BookAuthor varchar(10) not null,
BookInPrice varchar(10) not null,
check(BookMPrice > 0 ))
create table tb_Storage(
BookID int,
BookStoreMount int not null,
BookStoretime date not null,
primary key(BookID),
foreign key (BookID) references tb_Book
on delete cascade
on update cascade,
check (BookStoreMount > 0))
create table tb_Shopbasket(
ShopID int,
BookID int,
ShopMount int not null,
ShopPrice money not null,
primary key (ShopID,BookID),
foreign key (ShopID) references tb_SOrder
on delete cascade
on update cascade,
foreign Key (BookID) references tb_Book
on delete cascade
on update cascade,
check(ShopMount > 0 ),
check(ShopPrice > 0 ))
create table tb_SOrder(
ShopID int auto_increment,
ShopSum money not null,
ShopState varchar(20) default'未付款' not null,
primary key (ShopID),
check (ShopSum > 0),
check (ShopState in ('已付款','未付款')))
create table tb_Inputbasket(
InputID int,
BookID int,
InputPrice money not null,
InputMount int not null,
primary key(InputID,BookID),
foreign key(InputID) references tb_InOrder
on delete cascade
on update cascade,
foreign key(BookID) references tb_Book
on delete cascade
on update cascade,
check(InputPrice > 0),
check(InputMount > 0))
create table tb_InOrder(
InputID INTEGER PRIMARY KEY AUTOINCREMENT,
InputSum money not null,
InputState varchar(10) default'未付款',
check (InputSum > 0),
check (InputState in ('已付款','未付款','已退货','订单完成')))
create table tb_InOrder(
InputID int auto_increment,
InputSum money not null,
InputState varchar(10) default'未付款' not null,
primary key(InputID),
check (InputSum > 0),
check (InputState in ('已付款','未付款')))
需要进行修改的:
1.isbn需要加上unique约束
2.导入数据需要人工检查外键约束
3.主键自增需要换一个类型
INTEGER PRIMARY KEY
AUTOINCREMENT,并去掉后面的primay key
例子:
create table tb_InOrder(
InputID INTEGER PRIMARY KEY AUTOINCREMENT,
InputSum money not null,
InputState varchar(10) default’未付款’,
check (InputSum > 0),
check (InputState in (‘已付款’,‘未付款’,‘已退货’,‘订单完成’)))
4.money要改成real类型,去掉货币符号才可以获取值,获取用float类型获取,对应bind函数用double,column函数用double
目前遇到过的问题:
1.database locked?
不能同时在程序和sqlite browser中对数据库进行修改,sqlite不支持并行操作,需要重启?
2.?必须是英文字符
3.money要改成real类型,去掉货币符号才可以获取值,获取用float类型获取,对应bind函数用double,column函数用double
必须测试每个sql语句是否完成,用
rc = sqlite3_step(stmt);
if (rc == SQLITE_DONE)
{
printf(“成功创建新账户!”);
}
(storage的钱改为real