tags:

views:

35

answers:

1

I have a question I'm trying to have the q_id column take the value of the id column when a tag is submitted I have been trying to do this using PHP but I was thinking should I just add AUTO INCREMENT to the q_id column since but tables are updated when the tag is submited. or is this the wrong way to do it or is there a better way to do this?

Here is the MySQL tables below.

CREATE TABLE q_tags (
q_id INT UNSIGNED NOT NULL,
users_q_id INT UNSIGNED NOT NULL
);

CREATE TABLE tags (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
tag VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
A: 

AUTO INCREMENT is used mainly to avoid adding the same ID into a table, so that you can keep a loyal index. I'd suggest you add a primary key to the q_tags, and change the current q_id to a foreign key, so that it can become a reference to tags table.

EDIT :

CREATE TABLE q_tags (
q_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
t_id INT UNSIGNED NOT NULL,
users_q_id INT UNSIGNED NOT NULL,
PRIMARY KEY (q_id)
);

CREATE TABLE tags (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
tag VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);

t_id in the first table is the "foreign key". You can add it as a real mysql foreign key or just keep it this way (if you're planning on be able to "cascade delete" tags and t_tags related, it would matter)

yoda
How will my tables code look like?
tor
edited the post
yoda