473,785 Members | 2,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 11 '05 #1
3 1923

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 YourEmailAddres sHere" to ma*******@postg resql.org)

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.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
7741
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
9587
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 this? Thanks, Bob C.
28
3373
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 if the DDL for the tables and the SQL for the view.
2
2192
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, ie. individuals, organizations. In every case, there will be a many to many relationship between an entity table and the points table. Normally, this means creating an associative table for each relationship consisting of two columns; one FK...
7
7698
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 Impact Summary</td> </tr> <tr> <td colspan=2></td>
19
1401
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 only work for one Agency or one Publisher. Let's assume further that I cannot introduce a supertype (e.g. Employer) which holds the 1-to-n relationship. My preferrd solution is to have a foreign key in Emplyee that can either link to a primary...
14
4301
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 salvage the records from the many table and without going into detail, one of the reasons I can't do the opposite as there are records in the ONE table that I need to keep even if they don't have any child records in the MANY table. Below I created...
14
2905
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 furniture kind (chare + table + ...). Therefore, the room table should have Relation that point to several furniture kind, and the furniture table should have Relation to several rooms. Is there a way to define this kind of relation from one to...
6
3806
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 child FKs to other tables (no nulls will exist in these columns). Logically, one customer can have several accounts, but one account can
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10087
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.