Quantcast
Channel: MySQL implementing tables into database - Stack Overflow
Viewing all articles
Browse latest Browse all 2

MySQL implementing tables into database

$
0
0

I have to implement the tasks below:Task:At present, the database knows two types of messages:

  • Messages that a user posts and that are public for anyone and everyone to read
  • Messages that a user posts and that are non-public. These messages can only be read by users that the posting user has marked as friends.

In this step, you should add a third type of message. This third type of message should be readable by specified recipients only.This means the database needs to provide the following:

  • A way of distinguishing between the three types of messages. This involves a change to the Message table.
  • A way of specifying who the recipients of a particular message are. This will probably require an additional table.

All this must again be achieved with minimal amount of storage, i.e., you must choose the appropriate data types from the MySQL manual. You may assume that the total number of messages that are added over time may reach 1,000,000,000.Your job is to implement the necessary changes and additional table for this purpose and any keys and foreign key relationships required.

Here are my two tables first : User

CREATE TABLE IF NOT EXISTS `User` (`user_id` int(10) unsigned NOT NULL auto_increment,`given_name` varchar(60) default NULL,`surname` varchar(60) default NULL,`address` varchar(255) default NULL,`city_id` int(10) unsigned NOT NULL,`date_of_birth` datetime default NULL,`email` varchar(80) default NULL,PRIMARY KEY (`user_id`),KEY `ix_user_surname` (`surname`),KEY `ix_user_given_name` (`given_name`),KEY `ix_user_name` (`given_name`,`surname`),KEY `ix_user_date_of_birth` (`date_of_birth`),KEY `ix_user_email` (`email`),KEY `ix_user_city_id` (`city_id`)) ENGINE=InnoDB

2nd table :Message

CREATE TABLE IF NOT EXISTS `Message` (`message_id` int(10) unsigned NOT NULL auto_increment,`owner_id` int(10) unsigned default NULL,`subject` varchar(255) default NULL,`body` text,`posted` datetime default NULL,`is_public` tinyint(4) default '0',PRIMARY KEY (`message_id`),KEY `ix_message_owner_id` (`owner_id`)) ENGINE=InnoDB

MY SOLUTION: I was thinking of creating a new table called 'Message_level' and have columns 'message_level_id'(will refer to 1,2,3 as 1=public, 2=private, 3=specific) & 'message_level'(where it would state public,private and specific next to level). Then I can use the 'Message_level' as a foreign key into the 'Message' table and replace the 'is_public' column with 'message_level_id'.

Is my approach to this question right? is there another way I can do this to make it more efficient?

and how would I approach the second task of specifying who the recipients of a particular message are?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images