On Thursday 20 July 2006 07:19 am, Nicholas Vettese wrote:
> img_id    INT    NOT NULL auto_increment PRIMARY KEY,
> user_id   INT    NOT NULL,
> location  VARCHAR(255) NOT NULL,
> imgtype  VARCHAR(20) NOT NULL,
> img_tag  VARCHAR(50) NOT NULL,
> img_rate VARCHAR(20) NOT NULL,

good

> img_comments    VARCHAR(50) NOT NULL,

bzzt, bad!  Note here comment(s).  You have a 1 to many relationship, as one 
image can have many comments.  What you need to do is have a separate table 
for that:

CREATE TABLE image_comments (
  id SERIAL PRIMARY KEY,
  comment TEXT NOT NULL,
  image_id INT NOT NULL,
  CONSTRAINT `foreign_images_comments`
  FOREIGN KEY `foreign_images_comments` (`image_id`)
  REFERENCES `[image-table]` `img_id`
  ON DELETE CASCADE
);

then:

SELECT comment FROM image_comments WHERE image_id = [image_id_here];

Why?  Think about how you'd need to add comments.  You'd have 2 choices:

1) Shove all the comments in one column (get ready for a HUGE table)
2) Create a separate image row for each comment (lots of duplicate data, bad!)

> KEY (img_id);

Not needed, you already declared it a key above (PRIMARY KEY)

> Thanks for any help.
>
> nick

-- 
Chris White
PHP Programmer/DBoooooo
Interfuel

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to