| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

01-27-11, 06:51
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 30
|
|
|
Could anyone please tell me how to correctly create a table in MySQL?
|
|
Hi there,
I'm using MySQL Version 5.1.41 from XAMPP and it's really bugging me because I can't create a table.
(If it was in Oracle, it probably had been created by now or at least, better error msg and reference manual would have eased my pain.)
Code:
CREATE TABLE user
(userid NUMBER AUTO_INCREMENT,
username VARCHAR(255),
password VARCHAR(255),
isadmin INT,
PRIMARY KEY (userid));
I understand I'm a noob alright but seriously, I don't know what to modify.
I checked the reference manaual as well ( MySQL :: MySQL 5.1 Reference Manual :: 12.1.17 CREATE TABLE Syntax ) and maybe it's a lanugage problem but for the life of me, I can't understand what it meant!
One has to wonder why they didn't include any example.
I'm sorry if my post sounds quite negative but I find it extremely difficult to understand MySQL, sometimes. Hence, I'm so frustrated.
Anyway, please help me resolve this issue. Thanks in advance.
Best regards,
db_newbie
|
|

01-27-11, 06:59
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 2,408
|
|
NUMBER is not a valid data type in MySQL
The valid types are listed on the page you have linked to
|
|

01-27-11, 07:00
|
|
Jaded Developer
|
|
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
|
|
|
|
you can either do it through DDL directly in the MySQL command line
or you can run scripts containing the DDL
or you can use a front end tools such as Heidi SQL, MySQL Adminsitrator (or MySQL Query Bench), or any of the modelling tools.
many modelling tools require you to buy the tool to talk directly to the db, but most will generate the DDL that you can copy and paste into a tool that will directly run SQL.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
|
|

01-27-11, 07:01
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 30
|
|
Quote:
Originally Posted by shammat
NUMBER is not a valid data type in MySQL
The valid types are listed on the page you have linked to
|
Ahh, I see.
Thank you for that. So, I should be able to use the data type "NUMERIC", right?
Also, I don't think there's anything wrong with the syntax, is there?
Cheers and regards,
db_newbie
|
|

01-27-11, 07:05
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 30
|
|
Quote:
Originally Posted by healdem
you can either do it through DDL directly in the MySQL command line
or you can run scripts containing the DDL
or you can use a front end tools such as Heidi SQL, MySQL Adminsitrator (or MySQL Query Bench), or any of the modelling tools.
many modelling tools require you to buy the tool to talk directly to the db, but most will generate the DDL that you can copy and paste into a tool that will directly run SQL.
|
Oh ok. So, what you mean is..there are tools, softwares that will take in Oracle SQL (or any other SQL) and interpret them in MySQL compatible syntax, right?
That's something new for me. Thanks
Regards,
db_newbie
|
|

01-27-11, 07:06
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 2,408
|
|
Quote:
Originally Posted by db_newbie
Ahh, I see.
Thank you for that. So, I should be able to use the data type "NUMERIC", right?
|
For an autoincrement column I would use integer or even bigint depending on how many rows you expect.
Quote:
|
Also, I don't think there's anything wrong with the syntax, is there?
|
As far as I can see, no (apart from the wrong datatype)
Next time remember to post the error message as well
|
|

01-27-11, 08:36
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 30
|
|
Quote:
Originally Posted by shammat
For an autoincrement column I would use integer or even bigint depending on how many rows you expect.
As far as I can see, no (apart from the wrong datatype)
Next time remember to post the error message as well
|
Yes, I'll remember that  Was just too frustrated to think straight.
There aren't going to be that many rows, I think 2 digits would be enough.
In fact, this is a University assignment mainly for Web so I won't have to do much in MySQL (thankfully) apart from setting up the tables.
Thanks for all the replies, and cheers shammat.
You've helped me out, yet again
Regards,
db_newbie
|
|

01-27-11, 09:31
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
|
|
2 digits = TINYINT

|
|

01-27-11, 09:58
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 30
|
|
Quote:
Originally Posted by r937
2 digits = TINYINT

|
Does it mean I have to do like this
instead of ?
They're both are the same though, right?
Cheers and regards,
db_newbie
|
|

01-27-11, 10:02
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
|
|
Quote:
Originally Posted by db_newbie
They're both are the same though, right?
|
no, they are not
TINYINT holds numbers from -128 to 127 (if UNSIGNED, from 0 to 255)
INTEGER holds numbers from -2147483648 to 2147483647 (if UNSIGNED, from 0 to 4294967295)
the number in parentheses, like INT(2), does not do what you think it does

|
|

01-27-11, 10:02
|
|
Registered User
|
|
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
|
|
Try just:
Code:
CREATE TABLE test
(id TINYINT AUTO_INCREMENT,
...
);
|
|

01-27-11, 10:09
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 2,408
|
|
I would never use tinyint for a primary key column, not even for a university project.
The very marginal space savings do not justify the major problems that arise when you indeed want to insert more than 127 rows (that is including deleted rows).
So I would simply stick to integer
|
|

01-27-11, 10:19
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 30
|
|
Thanks for all your suggestions and I really wish MySQL Reference Manual was written by people in this forum. Would had been a lot easier to read cause I always get a "straight answer"
My lecturer also uses INT for the previous tables created. So, I'll probably stick with that. I'm sure you have to save disck space irl but atm, I don't have to worry about that. Since, this is a web dev assignment, I won't be inserting many rows either.
Although, hat TINYINT thing is pretty cool. Haven't heard of it before.
Thank you.
Regards,
db_newbie
|
|

01-27-11, 10:45
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 30
|
|
Actually, NVM
It was my mistake; an extra bracket.
Thank you all 
|
Last edited by db_newbie; 01-27-11 at 10:49.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|