PDA

View Full Version : Attempting to create my first hack from scratch...


Warlord
09-18-2004, 01:44 AM
I requested a hack in the requests forum and then thought I'd try to make it myself I went to a site to learn a little about mysql, but I have a question for anyone that can answer.

I took their mysql commands:


CREATE TABLE employees ( id tinyint(4) DEFAULT '0' NOT NULL AUTO_INCREMENT, first varchar(20), last varchar(20), address varchar(255), position varchar(50), PRIMARY KEY (id), UNIQUE id (id));INSERT INTO employees VALUES (1,'Bob','Smith','128 Here St, Cityname','Marketing Manager');


And edited them to reflect more of what I think I want my table to look like:


CREATE TABLE bios ( id tinyint(4) DEFAULT '0' NOT NULL AUTO_INCREMENT, name varchar(30), secretidentity varchar(50), groupaffiliation varchar(255), height varchar(10), weight varchar(10), haircolor varchar(20), eyecolor varchar(20), powers varchar(255), history varchar(255), PRIMARY KEY (id), UNIQUE id (id));

Now, I think I've figured out what most of these commands do, and what they stand for but a few I'm not to sure about, and I'd rather know what they all do then copy and paste them (I remember them better when I understand their function)

create table obviously creates the table (duh)

I assume the ( after bios lets phpMyAdmin know that the columns are about to follow?

What does id tinyint(4) DEFAULT '0' NOT NULL do? Is this one long command or 3? (Looks like three to me)

AUTO_INCREMENT sounds like it's telling phpMyAdmin that you want it to count and assign each row of data a number sequentially (1, 2, 3, etc) Yes?

varchar is obviously the character limit.. but what does var stand for? And why is the max limit only 255? How do you get around this max limit? phpMyAdmin said to use BLOB instead, but how do I use that?

What does PRIMARY KEY (id) do?

What does UNIQUE id (id) do?

The last) seems to be some sort of closing tag letting the server know it's done inserting columns. And I would guess the ; is to let the server know that the entire command is done?

Any help you all can provide is appreciated. After I have the answers to these questions, I will likely have more, so thanks in advance for you patience with me.

-WL

Colin F
09-18-2004, 06:36 AM
As you correctly interpreted, you are setting the columns in the ()'s
id... is one long command.

"id" is the name of the column
"tinyint" is the columntype (different types let you enter different types of data, some let you enter numbers (anything with *int), some let you enter text or text mixed with numbers, and so on)
(4) is the maximum length of the data entered in this column
DEFAULT'0' tells it to set this column to '0' if no data is entered (will be overriden by auto_increment)
auto_increment means it will assign a number automatically, starting with 1 and just always counting one up.
PRIMARY KEY and UNIQUE ID are indexes, which allow faster searching of the table, if only one of these values are searched for., UNIQUE ID additionally tells it that every entry into that column is unique

I missed some things, but maybe it helped you a bit. I'll try explain the rest when I have a bit more time.

Warlord
09-18-2004, 04:49 PM
Thanks for taking your time to help explain some of those things to me. :)

Warlord
09-24-2004, 06:54 PM
So, how do I get around the 255 character limit?

nexialys
09-24-2004, 07:13 PM
*varchar are limites to 255 characters wide - to have a larger set, use char(xxx) (or use mediumtext,text with larger bank)... btw, i think you'd be better read the entire documentation at mysql.com so you have a good overview on how to manage mysql queries...

http://dev.mysql.com/doc/mysql/en/index.html

Warlord
09-24-2004, 10:27 PM
Thanks for the quick reply nex, but I tried it and it seems char has the same 255 max character limit that varchar does. It instructed me to use BLOB, which I figured out how to do (it wasn't hard, just had to find where to change it, lol) but then there's nowhere to insert anything into that field, because it says "BINARY - Do not edit" instead of having a text input field.

I'll check that link out too, thanks for that. I'm gonna look up all of these type settings and see what I can dig up.