需求是这样的:
一个用户对应多个账单,账单对应多个账单分组和账单类型,一个用户又有多个账单分组,一个账单分组又有多个账单类型。我设计的表结构:
--用户
create table users
(
userId int auto_increment primary key,
userName varchar(50) not null ,
userPass varchar(50) not null
)--账单分组
create table billGroup
(
groupId int auto_increment primary key,
groupName varchar(50) not null,
userId int not null,
foreign key(userId) references users(userId)
)--账单类型
create table billType
(
typeId int auto_increment primary key,
typeName varchar(50) not null,
isIncome varchar(20) not null,
groupId int not null,
foreign key(groupId) references billGroup(groupId)
)--账单
create table bill
(
billId int auto_increment primary key,
amount varchar(20) not null,
content varchar(100) ,
groupId int not null,
typeId int  not null,
billDate varchar(30) not null,
userId int not null,
foreign key(groupId) references billGroup(groupId),
foreign key(typeId) references billType(typeId),
foreign key(userId) references users(userId)
)
欢迎大家提出改正的建议,谢谢~~