473,624 Members | 2,539 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 2294
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 "telefonnum ber" 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,tele fonnumber
where personname.pers on_id = telefonnumber.p erson_id
and personname.last name = '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
"telefonnum ber" 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
2931
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 defined in a different namespace from the element.
12
1457
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 experienced in relational modelling (10+ years) so this is not a case of not understanding the principles. Here is the problem stripped of irrelevant context. The problem below is simplified for the sake of the example so don't sweat the details.
3
9368
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 outs with datasets and datatables (and navigating through the filled datatable)... Just when I thought I had gotten the hang of it, another problem arose: I can't seem to access the "xsi:type" attribute. That is, the XML file looks
4
9160
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 be to set the intersecting table to have its own unique primary key. Right? OR
6
4863
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 the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
7
2686
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 the goals -- the make statement is mostly syntactic sugar for:: class <name> <tuple>: __metaclass__ = <callable>
3
5464
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 class simply to change its attribute is ugly IMO. I assume you can do this and then simply defer to the base class version but it's unwieldy so I'm wondering if there's a better way. Thanks in advance.
4
1424
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 through to the exception otherwise. This is just syntactic sugar. Example:
5
3047
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 temporary conversion folder. Then it converts it to the desired file format and copies the file to the output folder specified. Then it deletes the converted file from the temporary conversion folder. Then it attempts to delete the copied input file...
0
8246
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
8179
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8341
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
7174
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2612
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
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1489
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.