Two Laptop Bag
The moose likes JDBC and Relational Databases and the fly likes Create Table in MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Create Table in MySQL" Watch "Create Table in MySQL" New topic
Author

Create Table in MySQL

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
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

Joined: Oct 29, 2001
Posts: 9074
    
    9

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 ]

[How To Ask Questions On JavaRanch]
 
Have you tried LearnNowOnline? http://www.learnnowonline.com/
 
subject: Create Table in MySQL