我是设计数据库和 MySQL 的新手
所以为了简短起见,我所拥有的信息是AppId, Last Name, First Name, Gender, Age, DoB, Relation, School Name, School Address, School Phone Number, Teachers, Councilers, If they are in childcare
(AppID 是正在提交的应用程序 ID)
基本上这就是我如何看待所有事情的确定以及应该创建哪些表以最规范化
AppID -> Child ID
childID -> Last Name, FirstName, Gender, Age, DoB, Relation, School Name, Grade, Child Care
School Name -> Address School, School Phone Number, teacherID,counselorID
teacherID -> First Name, Last Name, Course
CounselorID -> First Name, Last Name, Counselor type
但是我不确定尝试完全标准化这是否是一个好主意,因为这是我正在帮助的一个相当小的组,这可能会导致加入表格比常规分组查找花费更长的时间并且可能占用更多空间。
另一个问题是 MySQL 只允许 1 个自动增量变量,我可以在查询中定义类似的东西,但如果可能的话,我宁愿不必这样做。2 个增量将是teacherID 和 CouncelorID
所以任何输入将不胜感激
编辑:这是基本结构,稍后还会添加修改属性,暂时放弃课程。谢谢
CREATE TABLE `Client_Child_Info` (
`FirstName` varchar(15) NOT NULL,
`LastName` varchar(15) NOT NULL,
`Gender` tinyint(1) NOT NULL,
`Age` tinyint(4) NOT NULL,
`DoB` date NOT NULL,
`Relation` varchar(15) NOT NULL,
`Grade` varchar(3) NOT NULL default 'NA',
`ChildCare` tinyint(1) NOT NULL default '0',
`ChildID` int(11) NOT NULL auto_increment,
PRIMARY KEY (`ChildID`),
KEY `Age` (`Age`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Basic Child Information' AUTO_INCREMENT=1 ;
CREATE TABLE `Client_Child_Schoolinfo` (
`SchoolID` int(11) NOT NULL,
`SchoolName` varchar(50) NOT NULL,
`SchoolAddress` varchar(50) default NULL,
`SchoolPhone` varchar(15) default NULL,
PRIMARY KEY (`SchoolID`),
KEY `SchoolName` (`SchoolName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='School Information for a given ID ';
CREATE TABLE `Client_child_teacher` (
`TeacherID` int(11) NOT NULL,
`FirstName` varchar(15) NOT NULL,
`LastName` varchar(15) NOT NULL,
`Guidance` tinyint(1) NOT NULL COMMENT 'determines if the person is a guidance councilor or teacher',
PRIMARY KEY (`TeacherID`),
KEY `Guidance` (`Guidance`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Teacher information';
CREATE TABLE `Client_RTchild` (
`AppID` int(11) NOT NULL,
`ChildID` int(11) NOT NULL auto_increment,
PRIMARY KEY (`ChildID`),
KEY `AppID` (`AppID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Reference Table Applicant to Client' AUTO_INCREMENT=1 ;
CREATE TABLE `Client_RTteacher` (
`SchoolID` int(11) NOT NULL,
`TeacherID` int(11) NOT NULL,
PRIMARY KEY (`TeacherID`),
KEY `SchoolID` (`SchoolID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Reference Table for teacher to school ';
CREATE TABLE `Client_RTschool` (
`ChildID` int(11) NOT NULL,
`SchoolID` int(11) NOT NULL auto_increment,
PRIMARY KEY (`SchoolID`),
KEY `ChildID` (`ChildID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Reference Table Child to SchoolID it is attending' AUTO_INCREMENT=1 ;
ALTER TABLE `Client_Child_Info`
ADD CONSTRAINT `Client_Child_Info_ibfk_1` FOREIGN KEY (`ChildID`) REFERENCES `Client_RTchild` (`ChildID`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `Client_Child_Schoolinfo`
ADD CONSTRAINT `Client_Child_Schoolinfo_ibfk_1` FOREIGN KEY (`SchoolID`) REFERENCES `Client_RTschool` (`SchoolID`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `Client_child_teacher`
ADD CONSTRAINT `Client_child_teacher_ibfk_1` FOREIGN KEY (`TeacherID`) REFERENCES `Client_RTteacher` (`TeacherID`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `Client_RTschool`
ADD CONSTRAINT `Client_RTschool_ibfk_1` FOREIGN KEY (`ChildID`) REFERENCES `Client_RTchild` (`ChildID`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `Client_RTteacher`
ADD CONSTRAINT `Client_RTteacher_ibfk_1` FOREIGN KEY (`SchoolID`) REFERENCES `Client_RTschool` (`SchoolID`) ON DELETE CASCADE ON UPDATE CASCADE;