View Full Version : HOW Do I do This Please?
Byronwells
01-22-2010, 02:25 AM
Alright guys
I would like to be able to add a new row to a existing mysql database..
I would like this row to be called Licence. This licence will store text in it...
I.e
Basic Resale Rights
Master Resale Rights
Personal Use Only
Private Label Rights
I know how to access the mysql database and find the right table to add it to... But it form there..
Old Pedant
01-22-2010, 03:18 AM
Non sequitir.
You can't add a *ROW* named anything.
Rows don't have names.
Do you mean you want to add a *FIELD* (also sometimes called--wrongly, in my opinion--"column") to one of your tables?
If you mean that, then most DB tools will help you do that.
If you really think you must do it via a query:
ALTER yourtablename ADD License VARCHAR(30);
Byronwells
01-22-2010, 03:23 AM
Non sequitir.
You can't add a *ROW* named anything.
Rows don't have names.
Do you mean you want to add a *FIELD* (also sometimes called--wrongly, in my opinion--"column") to one of your tables?
If you mean that, then most DB tools will help you do that.
If you really think you must do it via a query:
ALTER yourtablename ADD License VARCHAR(30);
Yes sorry I meant field.. Do I need to set any primary key, etc??
I't take it varchar(30): means how many charcters I am allowed to enter into that row.
Byronwells
01-22-2010, 03:29 AM
Non sequitir.
You can't add a *ROW* named anything.
Rows don't have names.
Do you mean you want to add a *FIELD* (also sometimes called--wrongly, in my opinion--"column") to one of your tables?
If you mean that, then most DB tools will help you do that.
If you really think you must do it via a query:
ALTER yourtablename ADD License VARCHAR(30);
One quick question
If at a later stage I wanted this new field called Licence to be reckonise by a drop down menu, do I need to do anything else to that field?
Or just go ahead and create the drop down menu, and then link it from there?
If you haven't already, please do check out and read through the MySQL manual (http://dev.mysql.com/doc/refman/5.1/en/).
To answer your questions, in order:
You do not have to ever have a PRIMARY KEY field, but it's a pretty standard way to have a unique value to link tables.
Yes, in VARCHAR(30), "30" is the limit of characters that will fit into that field.
No, you do not have to do anything special to pull this field into a drop down menu, save pulling the data via a scripting language like PHP, further format the data if necessary and then form a SELECT element. In this case it is a Very Good Idea to have a PK field to link to; this then becomes each respective OPTION value attribute so you can refer to this specific record.
Old Pedant
01-22-2010, 07:11 AM
All that bdl says is true, but if you expect to have hundreds of records using this field, then you might want to consider doing this:
CREATE TABLE Licenses (
licenseID INT PRIMARY KEY,
licenseName VARCHAR(30)
);
INSERT INTO Licenses ( licenseID, licenseName ) VALUES( 1, 'Basic Resale Rights' );
INSERT INTO Licenses ( licenseID, licenseName ) VALUES( 2, 'Master Resale Rights' );
INSERT INTO Licenses ( licenseID, licenseName ) VALUES( 3, 'Personal Use Only' );
INSERT INTO Licenses ( licenseID, licenseName ) VALUES( 4, 'Private Label Rights' );
ALTER TABLE yourtable ADD licenseID FOREIGN KEY REFERENCES Licenses(licenseID);
Now there are some interesting things you can do to create a drop down on a page that is already pre-SELECTed to refer to the appropriate value for a record in the "yourtable" table.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.