|
|
|
|
|
|
| Author |
Message |
Nicholas Vettese *nix forums beginner
Joined: 22 Jun 2006
Posts: 6
|
Posted: Thu Jul 20, 2006 2:19 pm Post subject:
Images Table
|
|
|
I am looking to create a database that holds the location of images on my server. I was wondering if anyone could help me understand if I am doing it correctly, and if I either need to add, change or remove something from the current table code.
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,
img_comments VARCHAR(50) NOT NULL,
KEY (img_id);
Thanks for any help.
nick |
|
| Back to top |
|
 |
Chris White *nix forums beginner
Joined: 21 Apr 2006
Posts: 43
|
Posted: Thu Jul 20, 2006 3:03 pm Post subject:
Re: Images Table
|
|
|
On Thursday 20 July 2006 07:19 am, Nicholas Vettese wrote:
| Quote: | 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
| Quote: | 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!)
Not needed, you already declared it a key above (PRIMARY KEY)
| Quote: | 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/mysql?unsub=gcdmg-mysql@m.gmane.org |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Mon Dec 01, 2008 6:45 pm | All times are GMT
|
|
Cheapest mobile phones | Loan | Mortgages | Loans | Credit Card Debt Consolidation
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|