File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes MySql QueryBrowser tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
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: 2510
    
  10

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 and ITIL foundation
youtube channel
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

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
 
jQuery in Action, 2nd edition
 
subject: MySql QueryBrowser tables