Win a copy of Microservices Testing (Live Project) this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

MySql QueryBrowser tables

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ;-)





 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 4323
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic