2

I have a "CustmerCrd" class that containing :

1.object of "Person" (another class) , let's call it per.
2.object of "Color" (enum type) , let's call it color.

My mission:

I had to create a DataBase table for this CustmerCrd class ,by using the "netbeans- create table dialog ". How do I do this?

my problem:

in the "Type" rubric (in the create table dialog) I have only the following types:

Date, TimeStamp, Boolean, Time, Decimal, Long varchacr, Char for bit data, VarChar for bit data, char, Real, Small int, BigInt, varChar, Blob, Double, integer, numeric, clob...

but i need "enum Color" type and "Person" type ,and of course it does not exist...

thank!

user3515151
  • 97
  • 2
  • 10

1 Answers1

1

You cannot easily model this as one table as you have two classes i.e. CustomerCrd and Person. Therefore you need two tables, one for each with CustomerCrd having a person_id column that is a foreign key to the primary key of the corresponding row in the Person table. The Color enum can probably be collapsed into an int, but that is not particularly good practice as if the enum changes so might the meaning of the int values, better to create a 3rd table for the enumerations of the color and use a foreign key,

adamretter
  • 3,885
  • 2
  • 23
  • 43
  • ok! 1.I will search on Google about this "foreign key" and how to use it. 2.Could you please explain briefly and practically what it means to me: 3rd table? thank! – user3515151 May 05 '14 at 09:59
  • By the 3rd table for Color. I mean if you have an enum with 3 values, i.e. 'Red', Blue' and 'Green'. It is better to create a table with two columns, id and name. Id should be a unique key, does not really matter what, but typically it will be a auto incrementing number, and the name column will be the name of the enum value. – adamretter May 05 '14 at 17:54