前提:一个通讯录中有N个联系人,一个联系人只在一个通讯录中。
linkuser ---——聯系人table
CREATE TABLE `linkuser ` (
`id` int(10) NOT NULL auto_increment,
`addressbookid ` int(11) default NULL,
`username` varchar(50) default NULL,
`tel28` varchar(50) default NULL,
`mobilenum` varchar(20) default NULL,
`country` varchar(10) default NULL,
`rate` varchar(15) default NULL,
`email` varchar(50) default NULL,
PRIMARY KEY (`id`),
KEY (`addressbookid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
addressbook ------通訊錄table
CREATE TABLE `addressbook` (
`id ` int(10) NOT NULL auto_increment,
`name` varchar(50) default NULL,
`userid` int(11) default NULL,
PRIMARY KEY (`id`),
KEY `userid` (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
//聲明外鍵、級聯刪除
ALTER TABLE `linkuser `
ADD FOREIGN KEY (`addressbookid `) REFERENCES `addressbook ` (`id `) ON DELETE CASCADE,