Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create Table in MySQL

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have several simple questions regarding creating tables in the MySQL.
1. For a variable of Java primitive int type, I should use INT or INTEGER? Do I have to specify the length of the field?
CREATE TABLE message_thread( thread_id INT or INTEGER NOT NULL );
2. A field in my table is for storing articles. Articles could be very long in variable length. I should use VARCHAR or TEXT? What about the length of the field?
3. For a variable of the Timestamp type, do I specify
CREATE TABLE message_thread( thread_creation_date TIMESTAMP NOT NULL );
What about the length of the field?
Thanks for your advices in advance.
 
Joe Ess
Bartender
Posts: 9300
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MySql has some excelent documentation
which answers your questions.
Originally posted by JiaPei Jen:

1. For a variable of Java primitive int type, I should use INT or INTEGER?
CREATE TABLE message_thread( thread_id INT or INTEGER NOT NULL );

From the documentation:

"M" Indicates the maximum display size. The maximum legal display size is 255.
INT[(M)] [UNSIGNED] [ZEROFILL]
A normal-size integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295.
INTEGER[(M)] [UNSIGNED] [ZEROFILL]
This is a synonym for INT.

Originally posted by JiaPei Jen:

Do I have to specify the length of the field?

Again, from the documentation:

Square brackets (`[' and `]') indicate parts of type specifiers that are optional.

And so on.
[ December 31, 2003: Message edited by: Joe Ess ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic