472,328 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 2229
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
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...
12
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...
3
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...
4
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...
6
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...
7
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...
3
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...
4
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...
5
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...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...

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.