Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 inserting multiple values into same field

Author  Topic 

sspr
Starting Member

7 Posts

Posted - 2006-02-15 : 05:05:57
can we insert multiple values into the same field. as we do for the mailing list. that is can we use commas to enter multiple values into the same field

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2006-02-15 : 05:19:38
Yes you can. you can have comma separated values in a column. but whats the requirement?
Go to Top of Page

sspr
Starting Member

7 Posts

Posted - 2006-02-15 : 06:03:12
i need to design a database to hold a persons mobile number and the services he has subscribed and my primary key should be only the mobile number not the combination of the number and the service. the person is allowed to subscribe for any number of services.... so i thought if i can find out a way to store the services in a comma separated format it would help.... i wouls like to know what is the exact insert statment.. i have to use
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-15 : 06:35:41
Have a seperate table to have personId and mobile number and insert data to it. Then using Join, you can retreive the mobile numbers


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sspr
Starting Member

7 Posts

Posted - 2006-02-15 : 06:56:09
sorry might be i did not explain the secnario correctly i want a table in which i have two fields mobile_numbers and service_ids. i need to insert multiple service id's into the service id column. say the user bearing the mobile number 988668866 has subscribed for stock info, cricket info ,astrology etc. now in my table i need to maintain his mobile number and id's of the services he has subscribed... 988668866 in mobile_numbers and some 12,13,14 in service_ids. now my doubt is...what datatype should i use for service_ids and in the insert statement how can i insert multiple entries into the service_ids..
Go to Top of Page

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2006-02-15 : 07:02:58
Hi,
you can have service_id as varchar
and insert a comma separated service_ids in that column.

but its better to opt for a normalized structure as it will be easy for you to retrieve information.
Go to Top of Page

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2006-02-15 : 07:10:15
This is a really bad idea. How are you going to maintain this information? What if you want a count by tel number of the number of services subscribed to, or you want to return all customers who have subscribed to a particular service? At best it's going to be unperformant, at worst it's going to involve some very convoluted SQL to extract your data.

Mark
Go to Top of Page

sspr
Starting Member

7 Posts

Posted - 2006-02-15 : 07:14:28
thanq shallu1_gupta.... that will solve my problem
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-02-15 : 07:19:58
Please do not put a list of values in 1 column! That is not good advice, and is not how databases are designed to be used. Do a google for "database norrmalization" and read up on it. Multiple values should be stored in multiple ROWS in a related table.
Go to Top of Page

sspr
Starting Member

7 Posts

Posted - 2006-02-15 : 07:22:19
sure i am really new to databases...so i came to know a new point...
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-02-15 : 08:38:59
Here's a pretty good link for you:

http://www.datamodel.org/NormalizationRules.html

Go to Top of Page
   

- Advertisement -