aspose file tools*
The moose likes JDBC and the fly likes Create Table in MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
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: 8710
    
    6

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 ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Create Table in MySQL
 
Similar Threads
What Would Cause A Method That Inserts Records To Throw An Exception?
Problem With Creating Table
Auto Increment ID Field Table in the Oracle Database
Passing date and time using Timestamp.
Hibernate Mapping Types.