This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes MySql QueryBrowser tables Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "MySql QueryBrowser tables" Watch "MySql QueryBrowser tables" New topic
Author

MySql QueryBrowser tables

Lenny Peter
Ranch Hand

Joined: Apr 22, 2008
Posts: 52
Kan I make 3 tables when I not have Integer as PK (table 2 and 3)?
Model number (78)
Car make (VW)
Car model (Lupo)
Car type (Waggon)
Model manufacture (Zumrette)
Price (123)
Scale (1:44)
Colour (Blue)
Weight (78)
Year (1977)
Country of manufacture (Germany)
Country of production (D)

1. table
Model number (78) PK
Car make (VW) FK
Car type (Waggon)
Model manufacture (Zumrette)
Price (123)
Scale (1:44)
Colour (Blue)
Weight (78)
Year (1977)
Country of manufacture (Germany) FK

2. table
Country of manufacture (Germany) PK
Country of production (D)

3. table
Car make (VW) PK
Car model (Lupo)


It is Ok with 3 tables?
Thanks ;-)





Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2343

Table 3 will not work. You have set MAKE as primary key. A primary key has to be unique, and VW has made more models than the LUPO.

Can I make 3 tables when I not have Integer as PK
Yes, that is possible. The primary key does not have to be an integer.


OCUP UML fundamental
ITIL foundation
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3652

You can mark any field in the table as a primary key or even have a composite (made up of 2+ fields) as a primary key.

One suggestion though: It's a good practice to always use an integer as a primary key since it makes joins to other tables easier. For example, if someone was placing an order for a car in your example, it saves space to have foreign key dependencies using integers over strings. The general rule is to always use integers as primary key unless you have an obvious 'natural key'. Although I've argued in the past there's really no such thing as a natural key, and integer keys should always be used. Either way, your model # can still be marked as a key (even if its not the primary key) with a uniqueness constraint.


My Blog: Down Home Country Coding with Scott Selikoff
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: MySql QueryBrowser tables
 
Similar Threads
Hibernate session
i want to create 2 dynamic drop down list
db desgin question: how to improve the relationship in this schema
Tricky Update Statement
Arraylist