If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > Multiple values in one attribute?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-06-11, 14:41
Asmaa Asmaa is offline
Registered User
 
Join Date: Dec 2011
Posts: 10
Multiple values in one attribute?

Hi
I know an attribute can only have one value. If for instance a customer in CUSTOMER table has more than one address or telephone number, how I can determine it before defining the attribute of the entity type? What would the source code of it be?
Code:
CREATE TABLE CUSTOMER
(
C_Id CHAR(10),
Name VARCHAR,
Tel_No VARCHAR /*how should I do it? */
);
INSERT INTO CUSTOMER
VALUES (
	'a12',
	'Middin',
	'09182343543 and 033334548934 how should I do it?'
	)
Reply With Quote
  #2 (permalink)  
Old 12-06-11, 15:19
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
Storing multiple values in a single column is considered bad DB design.

However if you really want to do it, you can use an array datatype:
Code:
CREATE TABLE customer
(
   C_Id   VARCHAR(10),
   Name   VARCHAR,
   Tel_No VARCHAR[]
);

INSERT INTO CUSTOMER
(c_id, name, tel_no)
VALUES 
(	'a12',
	'Middin',
	ARRAY ['09182343543','033334548934']
)
Note that you do not want CHAR(10) unless your values are always exactly 10 characters long.
Reply With Quote
  #3 (permalink)  
Old 12-07-11, 05:59
Asmaa Asmaa is offline
Registered User
 
Join Date: Dec 2011
Posts: 10
Thank you
In fact it cause me a lot of difficulty, but I have do deal with it.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On