laflair13 — 2012-04-16T16:01:52-04:00 — #1
Hopefully I can explain this right.
Right now I have a Category column in my table. Well I am wanting to take the "Category" from varchar to ENUM so I can change the values easily.
Can I do that without losing any data?
What I have right now is the Category column has comments but the comments wont let me add anything in it.
You can see what I mean from the screenshot below.
r937 — 2012-04-16T18:46:33-04:00 — #2
my advice is to stay well clear of ENUM
i doubt you can make the change easily in any case
that's not a mysql problem, though
VARCHAR can take anything
i would check your application code
laflair13 — 2012-04-16T23:01:50-04:00 — #3
Ok, Much appreciated. Any ideas of how I can add like 3 more items to the comments? I can to a SQL Query but will that mess up the existing data?
r937 — 2012-04-16T23:23:19-04:00 — #4
i'm not sure i understand what you mean by "3 more items"
your category column can hold as many items as you can fit into 2000 characters
oh, wait a sec... you're talking about the column comments!
column comments are strictly for documentation purposes
perhaps you could explain a bit more about the table that your category column is in, and how it is to be used?
laflair13 — 2012-04-17T07:18:30-04:00 — #5
I have a site where I add products through an admin panel. The "comments" are the categories that I use for a drop down. I need to add 3 more categories to that, But this is all I can see when I go to add it.
r937 — 2012-04-17T08:59:40-04:00 — #6
those are the comments of the category column, correct?
they have no bearing on what values the column can hold
what you should do is create a categories table, that has one row for every allowable category value
then tie this to your items table with a foreign key
laflair13 — 2012-08-13T13:27:22-04:00 — #7
I know this is a late reply, But is there any tutorial that will show me how to do that?
r937 — 2012-08-14T06:43:52-04:00 — #8
CREATE TABLE categories
( category VARCHAR(937) NOT NULL PRIMARY KEY
INSERT INTO categories VALUES
( 'Automation-Controls' )
,( 'Baggers' )
,( 'Bagger-Scales' )
,( 'Bins' )
,( 'Cappers' )
,( 'Case-Erectors' )
,( 'Carton-Formers' )
,( 'Check-Weighers' )
,( 'Complete-Lines' )
,( 'Confectionary-Equipment' )
,( 'Continuous-Mixers' )
,( 'Control-Panels' )
,( 'Conveyors' )
,( 'Cookie-Lines' )
,( 'Cooling-Tunnels' )
,( 'Cutting-Slitting ' )
ALTER TABLE new_equip
ADD CONSTRAINT cat_fk
FOREIGN KEY ( category )
REFERENCES categories ( category )
laflair13 — 2012-08-14T09:32:51-04:00 — #9
I appreciate that. My issue is I have everything going into one table. "new_equip" and in that table I have a column called Category and thats where all the categories are being stored. I have no clue how to edit it with using tables ad not messing up the site.
I have attached a screenshot to help it make more sense.
r937 — 2012-08-14T10:03:52-04:00 — #10
did you try running the code i gave you? what happened?