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.

 
Go Back  dBforums > Database Server Software > MySQL > Could anyone please tell me how to correctly create a table in MySQL?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-27-11, 06:51
db_newbie db_newbie is offline
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
Reply With Quote
  #2 (permalink)  
Old 01-27-11, 06:59
shammat shammat is offline
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
Reply With Quote
  #3 (permalink)  
Old 01-27-11, 07:00
healdem healdem is offline
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
Reply With Quote
  #4 (permalink)  
Old 01-27-11, 07:01
db_newbie db_newbie is offline
Registered User
 
Join Date: Nov 2010
Posts: 30
Quote:
Originally Posted by shammat View Post
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
Reply With Quote
  #5 (permalink)  
Old 01-27-11, 07:05
db_newbie db_newbie is offline
Registered User
 
Join Date: Nov 2010
Posts: 30
Quote:
Originally Posted by healdem View Post
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
Reply With Quote
  #6 (permalink)  
Old 01-27-11, 07:06
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
Quote:
Originally Posted by db_newbie View Post
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
Reply With Quote
  #7 (permalink)  
Old 01-27-11, 08:36
db_newbie db_newbie is offline
Registered User
 
Join Date: Nov 2010
Posts: 30
Quote:
Originally Posted by shammat View Post
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
Reply With Quote
  #8 (permalink)  
Old 01-27-11, 09:31
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
2 digits = TINYINT

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 01-27-11, 09:58
db_newbie db_newbie is offline
Registered User
 
Join Date: Nov 2010
Posts: 30
Quote:
Originally Posted by r937 View Post
2 digits = TINYINT

Does it mean I have to do like this
Code:
NUMBER TINYINT
instead of
Code:
NUMBER INT(2)
?

They're both are the same though, right?

Cheers and regards,
db_newbie
Reply With Quote
  #10 (permalink)  
Old 01-27-11, 10:02
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
Quote:
Originally Posted by db_newbie View Post
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

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #11 (permalink)  
Old 01-27-11, 10:02
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
Try just:

Code:
CREATE TABLE test
(id TINYINT AUTO_INCREMENT,
...
);
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #12 (permalink)  
Old 01-27-11, 10:09
shammat shammat is offline
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
Reply With Quote
  #13 (permalink)  
Old 01-27-11, 10:19
db_newbie db_newbie is offline
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
Reply With Quote
  #14 (permalink)  
Old 01-27-11, 10:45
db_newbie db_newbie is offline
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On