473,499 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to make an attribute of one table to relate with the attributes of other related table

Hello everyone,

I am a new user of postgresql... I have to create a table named person
like:

create table person (

personname varchar(40),

telefonnumber varchar(20)

);

Now, I have to create tables for personname and telefonnumber like:

create table personname (

firstname varchar(20),
lastname varchar(20)

);

and,

create table telefonnumber (

countrycode varchar(20),
areacode varchar(20),
number int4
);
Now, when the personname table has attributes:
firstname = 'John'
lastname= 'Paul'

and similarly somevalues for telefonnumber table,

i must have the value of personname attribute in person table as 'John
Paul' and the telefonnumber attribute of person table must be the
integration of attributes in the telefonnumber table.

Pls. guide me how to make this possible?...Is there any way to do so?

Thanx for spending ur valuable time and waiting for ur reply.

regards,
Jaggy Bala.
Jul 19 '05 #1
1 2279
Hello,
I am a new user of postgresql... I have to create a table named person
like:

create table person (
personname varchar(40),
telefonnumber varchar(20)
);

Now, I have to create tables for personname and telefonnumber like:

create table personname (
firstname varchar(20),
lastname varchar(20)
);

and,

create table telefonnumber (
countrycode varchar(20),
areacode varchar(20),
number int4
);

Now, when the personname table has attributes: firstname = 'John'
lastname= 'Paul'
and similarly somevalues for telefonnumber table,

i must have the value of personname attribute in person table as 'John
Paul' and the telefonnumber attribute of person table must be the
integration of attributes in the telefonnumber table.

Pls. guide me how to make this possible?...Is there any way to do so?


I don't understand why you wan't to do this that way, wouldn't it be
easier with a single table like :
create table person (
firstname varchar(20),
lastname varchar(20),
countrycode varchar(20),
areacode varchar(20),
number int4
);
?

Or, if you really want to use 3 tables, i suggest using one as an index
and others are refering to it using foreign keys. It can be useful if you
need several "telefonnumber" entries for one person.
For example :

create table person (
id serial primary key
);

create table personname (
person_id bigint references person,
firstname varchar(20),
lastname varchar(20)
);

create table telefonnumber (
person_id bigint references person,
countrycode varchar(20),
areacode varchar(20),
number int4
);

Then you can retrieve all the data for 'somebody' with something like :
select * from personname,telefonnumber
where personname.person_id = telefonnumber.person_id
and personname.lastname = 'somebody';

In this example, the table "person" is useless, since it would be better
to put the index in "personname".

Finally, if you really want to keep the tables as you describe and you
need to update the "person" table each time the "personname" or
"telefonnumber" table are updated, you can play with triggers but i don't
see any interest in this.

Hope this helps.

Bye.
Jul 19 '05 #2

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

Similar topics

4
2911
by: Lénaïc Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I've some namespace problems when defining default values for attributes. My problem seems to come from the fact that the attributes are...
12
1437
by: robertbrown1971 | last post by:
My company is working on a bond derivative portfolio analysis tool and we're facing a problem that I did not see adequately addressed any where in literature. I really did RTFM. I'm very...
3
9346
by: Carl Lindmark | last post by:
*Cross-posting from microsoft.public.dotnet.languages.csharp, since I believe the question is better suited in this XML group* Hello all, I'm having some problems understanding all the ins and...
4
9133
by: Fred | last post by:
Hi. What is the usual and what are the possible fields to use for the primary key of an intersecting table of a many-to-many relationship? I would think the typical, most common fields would...
6
4837
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
7
2673
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
3
5449
by: Michael Chambers | last post by:
Hi there, Is there a clean way to change a property or method's attribute in a derived class without redefining the property/method itself. That is, redefining the property/method in the derived...
4
1416
by: MonkeeSage | last post by:
Proposal: When an attribute lookup fails for an object, check the top-level (and local scope?) for a corresponding function or attribute and apply it as the called attribute if found, drop...
5
3032
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a .Net web service that converts the MODCA files to tif or png file format. This web service runs on a 2003 server. This web service first copies the MODCA file to be converted to a...
0
7134
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,...
0
7012
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7225
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7392
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...
0
5479
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4920
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3105
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...
0
307
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...

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.