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
 Database Design and Application Architecture
 using keywords

Author  Topic 

tt3955
Starting Member

2 Posts

Posted - 2011-10-23 : 17:32:04
I'm just wondering if someone can give me some help on the structure of a keyword system to use.

If I wanted to allow users to enter keywords and have it attached to a profile how would I go about setting up a table to do this?

I already have an ID for a primary key. Should I build the table so that there are two columns. One is the ID(as a foreign key) and the other is a keyword. Each time a user enters a new keyword the table would add their ID and then the keyword in the next column. Is there a better way to do this? I can see this table getting very long since there are multiple users and each line only holds 1 keyword.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-24 : 04:07:25
can a user have multiple keywords? Also i think there should be a bridge table relating users to keywords if keywords can be shared between users

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tt3955
Starting Member

2 Posts

Posted - 2011-10-24 : 17:15:05
Sorry, I guess I didn't make it clear.

Yes, there can be multiple keywords per user and there's where my confusion is coming into play.

For example, say this is the table with a user ID that is unique to every user, and a keyword which they can enter.

User ID Keyword
1 computer
1 keyboard
2 laptop
1 tv
3 games

Basically, what I was planning on doing to see each user's keywords is querying something like "select keyword where user_ID="1" which would result in "computer keyboard tv"

While this may be easy, is there a more "proper" way to do something like this?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-25 : 00:01:53
you can retrieve like that using query below

SELECT STUFF((SELECT ' ' + Keyword FROM table WHERE User_ID=1 FOR XML PATH('')),1,1,'')


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -