Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-11-2008
Member
 
Join Date: Nov 2008
Posts: 1,054
Combining two tables

I want to make an association type "a message can have zero or more comment" but I have no idea how to do it. I managed to lay it after my research but I am not sure that it do what I want:

Code:
CREATE TABLE `messageboard` { 
`id_messageboard` int UNSIGNED NOT NULL AUTO_INCREMENT, 
`ip` varchar(15) NOT NULL, 
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, 
`pseudo` varchar(20) NOT NULL, 
`mess` text NOT NULL, 
PRIMARY KEY (`id_messageboard`) 
} ENGINE=InnoDB DEFAULT CHARSET=utf8; 

CREATE TABLE `comments` { 
`id_comments`   int UNSIGNED NOT NULL AUTO_INCREMENT, 
`id_messageboard` int UNSIGNED NOT NULL, 
`ip` varchar(15) NOT NULL, 
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, 
`pseudo` varchar(20) NOT NULL, 
`message` text NOT NULL, 
PRIMARY KEY (`id_comments`), 
FOREIGN KEY (`id_messageboard`) REFERENCES `messageboard` (`id_messageboard`) ON DELETE NO ACTION ON UPDATE NO ACTION 
} ENGINE=InnoDB DEFAULT CHARSET=utf8;
So now, I am or not?
Reply With Quote
  #2  
Old 26-11-2008
Member
 
Join Date: May 2008
Posts: 669
Re: Combining two tables

There is just something that I can not capture the "NO ACTION ON DELETE ..."
If you delete the message, it will trigger or do something that will make you do your work.
Reply With Quote
  #3  
Old 26-11-2008
Member
 
Join Date: Nov 2008
Posts: 1,054
Re: Combining two tables

Yes but that's because I do not know what to put in place. But yes you're right, we need something happens when a message is deleted.
Reply With Quote
  #4  
Old 26-11-2008
Member
 
Join Date: May 2008
Posts: 669
Re: Combining two tables

Given that the last BDD on which I worked were SQL Server and Oracle, I am a little rusty in MySQL. But I suppose there must be the equivalent of trigger to trigger removal of comments that are linked to this message. And in general the DBMS is even able to do it alone.
Reply With Quote
  #5  
Old 26-11-2008
Member
 
Join Date: Nov 2008
Posts: 1,054
Re: Combining two tables

"ON DELETE CASCADE"

I think that's right. Otherwise, you think it will work if I make my tables like that?
Reply With Quote
  #6  
Old 26-11-2008
Member
 
Join Date: May 2008
Posts: 669
Re: Combining two tables

Yeah that's right

(Same syntax as Oracle and SQL Server )
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Combining two tables"
Thread Thread Starter Forum Replies Last Post
Excel 2010 combining data kraser Windows Software 1 27-02-2012 02:35 PM
Combining With Other Anti Malware Snowie Networking & Security 6 12-06-2011 10:17 AM
Combining VPN with JonDo ittiandro Networking & Security 1 08-06-2011 03:54 AM
Combining PSU rails together Pranvi Hardware Peripherals 4 02-05-2011 08:20 PM
Combining SSH and Cron void Software Development 3 06-08-2010 01:44 AM


All times are GMT +5.5. The time now is 08:18 AM.