Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating table

 
Candy Bortniker
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just learning Java, through a college course. I have been given an assignment to create two tables and populate them with information. I have spent a litte time searching the API hoping for some help but I didn't really know where to start looking. What I need to know first is how to create the table. I know to use ("CREATE TABLE <table name> ()"); Do I put the name of each column in the ()? Are they separated by commas? Along with the name do I put the type and the size?
I have more questions if you don't mind helping, but this could get me started.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd recommend taking a look at The Creating Tables section at SQLCourse.com.
And perhaps a simple example will help. The following SQL statement would work to create a new table named student with three columns - idNo, fName, and lName - in a MySQL database.
create table student (
  idNo varchar(11) not null,
  fName varchar(32),
  lName varchar(32)
);
This statement specifies that idNo is a char field up to 11 characters big that is not allowed to be empty (not null). fName and lName are fields up to 32 characters each.
Available column types do differ between different database vendors. For example, Oracle has a column type called varchar2, while MySQL does not. So, a table creation statement for one database vendor might not work on another.
When figuring out table creation statements, it can be nice to have the documentation at hand. The documentation for the MySQL Column Types can be found at http://www.mysql.com/doc/en/Column_types.html
Figuring it out?
[ April 26, 2003: Message edited by: Dirk Schreckmann ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic