Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Create Table in MySQL  RSS feed

 
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.
 
Bartender
Posts: 9521
12
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!