create two tables, airportservices and userairportservices
airportservices
AIRPORT_SERVICE_ID
AIPORT_ID
SERVICE_ID
userairportservices
USER_AIRPORT_SERVICE_ID
USER_ID
AIRPORT_SERVICE_ID
this will allow airport services to hold the services at the airport and the userairportservices to hold the relationship between user and airport_service
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
yep that looks good, the other way to do it would be to replace user_id in user_airport_services with user_airports_link, but there could be a constraint violation if the user was ever removed from an airport
what do you mean as far as the user inserting into the tables?
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
the airport services will have something like this
as_id a_id s_id
1 1 1
2 1 2
services
1 movies on board
2 international flights
userairportservices
uas_id user_id as_id
1 1 2
this means the airport offers two services, but the user only has access to 1 service, userid of 1 can only have a service of international flights at airportid 1, but airportid 1 offers 2 services
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
But the choice of which services they have should only be made after the airport relationship is defined.
i thought this meant airports have different services
this table structure can be used, or you can use this one
userairportservices
user_airport_service_id
user_id
airport_id
service_id
and drop the airportservices table
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
yes, you can drop users_airports_link
i don't know which 3:37 post is, but i assume its the one with the data
airports
aid airport code
1 hartsfield ATL
services
1 movies on board
2 international flights
users
uid usr_fname
1 john
2 jane
userairportservices
uas_id user_id service_id airport_id
1 1 2 1
2 2 1 1
2 2 2 1
this will show user_id 1 (john) has international flights at atl
this will show user_id 2 (jane) has international flights and movies at atl
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
also your city, country, and area code tables are out of sync
the way you have it, a city could have a different postal code, different country and different area code
the relationship should be
country --> areacode --> city -->postalcode
a country has area codes, which has cities, which have postal codes
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
sorry i mistyped my id from before, you were correct, it should be 1 2 3
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
yes sequential inserts into the rest of the tables after user, the ripple effect you are wanting, is only on updates and deletes, you can't necessarily insert and populate tables the way you are wanting without triggers, but thats a whole different story
now the location thing
what you were allowing with the way you had it before was a user to have a city that wouldn't belong to the correct country, postal, or area code and vice versa
think of it just as you stated it, a country has area codes, area codes have cities, cities have postal codes
(the area code doesn't necessarily match because its phone based, but anyways)
take for example there is a toronto us and canada
we will take area codes out of this example
country
1 us
2 canada
cities
cityid cityname countryid
1 toronto 1
2 toronto 2
postal codes
postalcodeid postalcode cityid
1 11115 1
2 11116 1
3 45428 2
that is the concept, also you i don't know about how canada is, but countries have states, states have cities, cities have postal codes, which maybe states is what you are meaning area codes
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
Lol always helps to have a second set of eyes.
Sure just give the link for your new diagram and i'll check it out.
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
area codes are a little tricky and sort of hard to get a direct correlation with a physical location
i think it would be best to leave them separate
for example atlanta has 3 area codes, but those area codes are also used in other cities, suburbs also share those 3 area codes, multiple cities, sharing duplicate multiple area codes
plus a user can have an area code from another place if they moved
very good, aren't you happy with this diagram compared to how you started?
so what is your next step with this?
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143