我正在为一个网站的通知系统工作,这里是基本的想法; 我有一个表Notifications
其中我有列如何设计一个通知系统表的一对多数据库关系?
notif_msgnotif_urlreceiver_s
其中receiver_s
将具有多个逗号分隔值。但是,我知道这不是个好主意,并且建议有一个不同的表来存储接收者。按照指定here创建一对多关系。然而,我很困惑,因为我不是MySQL的专家。 这里是我的创建语句如何看起来像上面的链接的例子;
create table `notifications` (`id` int unsigned not null auto_increment,`notif_msg` varchar(500) not null,`notif_url` varchar(100) not null, primary key(`id`));
create table `notifications_target` (`id` int unsigned not null auto_increment, `notification_id` int unsigned not null, `receiver` varchar(25) not null, index pn_user_index(`notification_id`), foreign key (`notification_id`) references notifications(`id`) on delete cascade,primary key(`id`));
我需要知道几件事情;
- 什么功能请问
index
服务在那里? - 从这里,我怎么插入
notifications
表和多个接收器价值为notif_msg
,notif_url
到receivers
列notification_target
在notifications
表引用一个特定的行? - 如何从
notifications
表及其对应的表中的receiver
表中返回值?
这里就是我打算让与特定的用户,并在同一时间的所有用户面前现在notifications
;
选择
notif_msg
,notif_url
FROMnotifications
WHERE receiver_s = somename和WHERE receiver_s =”'
我怎么做到这一点,现在我有接收器不同的表?
现在即时得到它。我们在通知中插入值并将其保存在notification_id字段中。真棒。 – Victor
它使查询更快。看看我在答案中添加的链接,了解它是如何工作的。 –