472,793 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,793 software developers and data experts.

many columns with references to one table

Hi,

What is the problem with the following table declaration?

CREATE TABLE persons (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
bdate DATE,
address INTEGER REFERENCES addresses,
phonepriv INTEGER REFERENCES phones,
phoneday INTEGER REFERENCES phones,
phonemobil INTEGER REFERENCES phones,
email INTEGER REFERENCES emails,
mate INTEGER REFERENCES persons,
updated DATE NOT NULL
);

My problem is that the references to the phones table do not get
restricted, i.e. I can insert any value in the phone*-fields, while the
references to the other tables are restricted to values that allready
exists. The table declaration of phones should be all right, it has a
primary key defined like every other tables I have. Is there a
restriciton that no more then 1 column may reference an other table?

Regards

Andreas Fromm

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #1
3 1838

On Tue, 26 Aug 2003, Andreas Fromm wrote:
Hi,

What is the problem with the following table declaration?

CREATE TABLE persons (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
bdate DATE,
address INTEGER REFERENCES addresses,
phonepriv INTEGER REFERENCES phones,
phoneday INTEGER REFERENCES phones,
phonemobil INTEGER REFERENCES phones,
email INTEGER REFERENCES emails,
mate INTEGER REFERENCES persons,
updated DATE NOT NULL
);

My problem is that the references to the phones table do not get
restricted, i.e. I can insert any value in the phone*-fields, while the
references to the other tables are restricted to values that allready
exists. The table declaration of phones should be all right, it has a
primary key defined like every other tables I have. Is there a
restriciton that no more then 1 column may reference an other table?


Not as far as I know (and I've done multiple references to the same table
in the pash) with the exception that versions before either 7.3 or 7.2 are
going to have problems with referential actions other than NO ACTION in
such cases.

Can you make a complete standalone example?
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #2
Tom Lane wrote:
Andreas Fromm <An***********@physik.uni-erlangen.de> writes:

My problem is that the references to the phones table do not get
restricted, i.e. I can insert any value in the phone*-fields, while the
references to the other tables are restricted to values that allready
exists.


Hard to believe --- and I couldn't reproduce it here. What PG version
are you using? Can you show us a complete example?

regards, tom lane

Well, the demonstration effect...
After a complete rewrite of my Database-generating sql-file the problem
is solved. Don't know what I did wrong the first time, but it's working
now. The curious thing is that I didn't made anything different in this
part.

Thanks

Andreas
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #3
You haven't given the table/column that it references, just the column I
assume.

Andreas Fromm wrote:
Hi,

What is the problem with the following table declaration?

CREATE TABLE persons (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
bdate DATE,
address INTEGER REFERENCES addresses,
phonepriv INTEGER REFERENCES phones,
phoneday INTEGER REFERENCES phones,
phonemobil INTEGER REFERENCES phones,
email INTEGER REFERENCES emails,
mate INTEGER REFERENCES persons,
updated DATE NOT NULL
);

My problem is that the references to the phones table do not get
restricted, i.e. I can insert any value in the phone*-fields, while
the references to the other tables are restricted to values that
allready exists. The table declaration of phones should be all right,
it has a primary key defined like every other tables I have. Is there
a restriciton that no more then 1 column may reference an other table?

Regards

Andreas Fromm

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 11 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Guinness Mann | last post by:
I know this is a self join, but I can't remember exactly how it goes. Could someone help me out? create table A { int idA, varchar(30) dataA } create table B
9
by: Bob C. | last post by:
I want to create a 1-many relationship. Parent table has a primary key, child table has no primary key. The child table does have an index with all four fields of the parent's PK. How can I do...
28
by: Keith | last post by:
I am having a problem creating a many-to-many-to-many type relationship. It works fine, but when I create a view to query it and test it, it does not generate the results I expected. Below...
2
by: MRG | last post by:
I have a geographic points table containing point records with latitude and longitude points. I also have several other tables containing entities that will relate to points in the points table,...
7
by: Billy Jacobs | last post by:
I am using a datagrid to display some data. I need to create 2 header rows for this grid with columns of varying spans. In html it would be the following. <Table> <tr> <td colspan=8>Official...
19
by: martind-crap1 | last post by:
Hi, What is the best way to model this: Assume I have two objects: Agency and Publisher, and both have a 1-to-n relationship to Employee. This is a true 1-to-n relationship, as each Employee can...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
14
by: Sharon | last post by:
I have two tables in the DataSet, the first present rooms and the other furniture kinds. Furniture kind, like chare, can be in more then one room. And specific room can contain more then one...
6
by: BD | last post by:
Hi, all. I need to enforce a one-to-many relationship on 2 tables, with a join table. Say the join table contains account information. It has cust_no and acct_no. Both cust_no and acct_no are...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.