Results 1 to 6 of 6

Thread: Combining two tables

  1. #1
    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?

  2. #2
    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.

  3. #3
    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.

  4. #4
    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.

  5. #5
    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?

  6. #6
    Join Date
    May 2008
    Posts
    669

    Re: Combining two tables

    Yeah that's right

    (Same syntax as Oracle and SQL Server )

Similar Threads

  1. Excel 2010 combining data
    By kraser in forum Windows Software
    Replies: 1
    Last Post: 27-02-2012, 02:35 PM
  2. Combining With Other Anti Malware
    By Snowie in forum Networking & Security
    Replies: 6
    Last Post: 12-06-2011, 10:17 AM
  3. Combining VPN with JonDo
    By ittiandro in forum Networking & Security
    Replies: 1
    Last Post: 08-06-2011, 03:54 AM
  4. Combining PSU rails together
    By Pranvi in forum Hardware Peripherals
    Replies: 4
    Last Post: 02-05-2011, 08:20 PM
  5. Combining SSH and Cron
    By void in forum Software Development
    Replies: 3
    Last Post: 06-08-2010, 01:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,752,124,250.11876 seconds with 16 queries