Обсуждение: What to do with no foreign keys
If I have two tables, which are like this: baseball_team ------------- team_name number_of_players games_played total_runs baseball_game ------------- home_team_name visitor_team_name home_runs visitor_runs How can I insure that for example "home_team_name" is one of "baseball_team.team_name"? I have seen in books things like: PRIMARY KEY: home_team FOREIGN KEY: home_team JOIN TO baseball_team.team_name is there anyway to do this in postgresql? Bascially I have like 12 tables, and alot of them have a field "username". I want to insure that "username" in all tables, is a valid username in "passwd.username". Brian /-------------------------- signal@shreve.net -----------------------------\ | Brian Feeny | USR TC Hubs | ShreveNet Inc. (318)222-2638 | | Network Administrator | Perl, Linux | Web hosting, online stores, | | ShreveNet Inc. | USR Pilot | Dial-Up 14.4-56k, ISDN & LANs | | 89 CRX DX w/MPFI, lots of |-=*:Quake:*=-| http://www.shreve.net/ | | mods/Homepage coming soon |LordSignal/SN| Quake server: 208.206.76.47 | \-------------------------- 318-222-2638 x109 -----------------------------/
Hello Brian, giovedì, 9 luglio 98, you wrote: B> If I have two tables, which are like this: B> baseball_team B> ------------- B> team_name B> number_of_players B> games_played B> total_runs B> baseball_game B> ------------- B> home_team_name B> visitor_team_name B> home_runs B> visitor_runs B> How can I insure that for example "home_team_name" is one of B> "baseball_team.team_name"? B> I have seen in books things like: B> PRIMARY KEY: home_team B> FOREIGN KEY: home_team JOIN TO baseball_team.team_name B> is there anyway to do this in postgresql? Bascially I have like 12 tables, B> and alot of them have a field "username". I want to insure that B> "username" in all tables, is a valid username in "passwd.username". B> Brian B> /-------------------------- signal@shreve.net -----------------------------\ B> | Brian Feeny | USR TC Hubs | ShreveNet Inc. (318)222-2638 | B> | Network Administrator | Perl, Linux | Web hosting, online stores, | B> | ShreveNet Inc. | USR Pilot | Dial-Up 14.4-56k, ISDN & LANs | B> | 89 CRX DX w/MPFI, lots of |-=*:Quake:*=-| http://www.shreve.net/ | B> | mods/Homepage coming soon |LordSignal/SN| Quake server: 208.206.76.47 | B> \-------------------------- 318-222-2638 x109 -----------------------------/ Take a look at .../contrib/spi/refint.example. Best regards, Jose' mailto:sferac@bo.nettuno.it
> How can I insure that for example "home_team_name" is one of > "baseball_team.team_name"? > > I have seen in books things like: > > PRIMARY KEY: home_team > FOREIGN KEY: home_team JOIN TO baseball_team.team_name > > is there anyway to do this in postgresql? I asked the same question a week or two ago. If I remember correctly, foreign keys are not yet part of PostgreSQL, but they will be part of the next release. It was suggested that it would be appropriate to handle these sorts of issues within your code at this point. Bruce Tong | Got me an office; I'm there late at night. Systems Programmer | Just send me e-mail, maybe I'll write. Electronic Vision / FITNE | zztong@laxmi.ev.net | -- Joe Walsh for the 21st Century
On Fri, 10 Jul 1998, Bruce Tong wrote: > > How can I insure that for example "home_team_name" is one of > > "baseball_team.team_name"? > > > > I have seen in books things like: > > > > PRIMARY KEY: home_team > > FOREIGN KEY: home_team JOIN TO baseball_team.team_name > > > > is there anyway to do this in postgresql? > > I asked the same question a week or two ago. If I remember correctly, > foreign keys are not yet part of PostgreSQL, but they will be part of the > next release. It was suggested that it would be appropriate to handle > these sorts of issues within your code at this point. > Ok, so there is no way to tie values between tables..........I can live with that. I think Postgres is really going to be something in a few years, I mean it already is, but once outer joins, foreign keys and a few of the other features are worked in, I think there will be alot of places taking a second look and trying Postgres. We use a billing system for ISP's called Platypus (www.boardtown.com). It uses MS SQL server as its backend. Many people that use platypus would prefer it to use Postgres. One of the reasons we beleive boardtown doesn't support Postgres at this time is because of a few features SQL server has over Postgres, and they would have to work around those. Brian > > Bruce Tong | Got me an office; I'm there late at night. > Systems Programmer | Just send me e-mail, maybe I'll write. > Electronic Vision / FITNE | > zztong@laxmi.ev.net | -- Joe Walsh for the 21st Century > > /-------------------------- signal@shreve.net -----------------------------\ | Brian Feeny | USR TC Hubs | ShreveNet Inc. (318)222-2638 | | Network Administrator | Perl, Linux | Web hosting, online stores, | | ShreveNet Inc. | USR Pilot | Dial-Up 14.4-56k, ISDN & LANs | | 89 CRX DX w/MPFI, lots of |-=*:Quake:*=-| http://www.shreve.net/ | | mods/Homepage coming soon |LordSignal/SN| Quake server: 208.206.76.47 | \-------------------------- 318-222-2638 x109 -----------------------------/
> B> PRIMARY KEY: home_team > B> FOREIGN KEY: home_team JOIN TO baseball_team.team_name > Take a look at .../contrib/spi/refint.example. I don't suppose you could post the full URL for that? I checked the examples I use frequently, and I'm not familiar with where that one might be. Bruce Tong | Got me an office; I'm there late at night. Systems Programmer | Just send me e-mail, maybe I'll write. Electronic Vision / FITNE | zztong@laxmi.ev.net | -- Joe Walsh for the 21st Century
> > B> PRIMARY KEY: home_team > > B> FOREIGN KEY: home_team JOIN TO baseball_team.team_name > > > Take a look at .../contrib/spi/refint.example. > > I don't suppose you could post the full URL for that? I checked the > examples I use frequently, and I'm not familiar with where that one might > be. It's not an URL, it's a path. [YOUR POSTGRES SRC DIR]/contrib/spi/ Antonio Garcia Mari Mallorca (Spain)