1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

simple/imp issue in db design

Discussion in 'Databases' started by varun8211, Dec 5, 2006.

  1. #1
    Most of the registration process on websites, ask you for the country name from drop down. My question is , should we design our db like this:
    Table 1: Country (countryID, countryName)
    Table 2: Registration(Name, email ... Country(Id/Name) .

    So, it should be countryId in the registration table or countryName ?

    Which is the best approach ?
     
    varun8211, Dec 5, 2006 IP
  2. Scolls

    Scolls Guest

    Messages:
    70
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    CountryID would be smaller, so it would be best I'd say. int(3) perhaps? All you need is an int just big enough to be able to represent the number of countries in your drop-down.

    So to save yourself any trouble of having to look up a countryID in your country table after the form gets submitted, just pre-populate your form with these id's corresponding the names, eg <option value="1">USA</option> etc.
     
    Scolls, Dec 5, 2006 IP
  3. varun8211

    varun8211 Peon

    Messages:
    483
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I thought so, but what if we need to search by country name ?
     
    varun8211, Dec 5, 2006 IP
  4. Scolls

    Scolls Guest

    Messages:
    70
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well, you've got countryID common to both tables, so for argument's sakes if you were wanting to find all members from Ireland, you'd search something like this:

    select r.* from registration r left join country c using(countryid) where c.countryname="ireland"
     
    Scolls, Dec 5, 2006 IP