473,386 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Search Text in Database

Hi,
I would like to use keywords inside a record to search for - like a
searchengine.
How can I design the table? Right now I would store data in Memo-Column in a
format like ";apple;banana;lemon;". I would use a INSTR(ring)-function - but
I wonder if the performance is still OK then - even when I index the field.
Are there maybe even better ways?

Thanx in advance.
Greg
Jul 20 '05 #1
4 1377
Each field in a given row should store one piece of information. Seperating
your data with semicolons suggests that your storing multiple piecies of
data in a field that should only be storing a single peice of data. It
defeats the puprose of a relational database. Instead you probably want to
add a second table that will have a one to many or a third table to setup a
many to many relationship with your first table and possibly second. Here
are two table ideas but without your DDL I can't know what it is your trying
to do so I'm guessing. If you need more information provide your DDL (i.e.
your create statements, and some insert statements with sample data).

CREATE TABLE Food_Type
(
ID INT IDENTITY PRIMARY KEY NOT NULL,
Name VARCHAR(50) NOT NULL
)

CREATE TABLE Food_Attributes
(
ID INT IDENTITY PRIMARY KEY NOT NULL,
Attribute VARCHAR(50) NOT NULL,
Food_Type_ID INT NOT NULL
)

Then your data could look like this.

INSERT INTO Food_Type VALUES ('Dinner')
INSERT INTO Food_Type VALUES ('Lunch')
INSERT INTO Food_Type VALUES ('Snack')
INSERT INTO Food_Attributes VALUES ('Chicken',1)
INSERT INTO Food_Attributes VALUES ('Sandwich',2)
INSERT INTO Food_Attributes VALUES ('Orange',3)
INSERT INTO Food_Attributes VALUES ('Bannana',3)
INSERT INTO Food_Attributes VALUES ('Apple',3)
Now you have two tables that look roughly like this:

ID Name
---------------------------------------
1 Dinner
2 Lunch
3 Snack

ID Attribute Food_Type_ID
----------------------------------------
1 Chicken 1
2 Sandwich 2
3 Orange 3
4 Bannana 3
5 Apple 3

Then if you wanted you could select all the food attributes that belong to a
snack

SELECT Food_Attributes.Attribute
FROM Food_Attributes
JOIN Food_Type ON Food_Type.ID = Food_Attributes.Food_Type_ID
WHERE Food_Type.Name = 'Snack'
This will return a result set like this

Attribute
------------------
Orange
Bannana
Apple

Best,
Muhd

"Greg Cyrus" <no****@muelltonne.de> wrote in message
news:ck*************@news.t-online.com...
Hi,
I would like to use keywords inside a record to search for - like a
searchengine.
How can I design the table? Right now I would store data in Memo-Column in
a format like ";apple;banana;lemon;". I would use a INSTR(ring)-function -
but I wonder if the performance is still OK then - even when I index the
field. Are there maybe even better ways?

Thanx in advance.
Greg

Jul 20 '05 #2

"Greg Cyrus" <no****@muelltonne.de> wrote in message
news:ck*************@news.t-online.com...
Hi,
I would like to use keywords inside a record to search for - like a
searchengine.
How can I design the table? Right now I would store data in Memo-Column in
a format like ";apple;banana;lemon;". I would use a INSTR(ring)-function -
but I wonder if the performance is still OK then - even when I index the
field. Are there maybe even better ways?

Thanx in advance.
Greg


Memo and INSTR() are Access terms, I believe, not MSSQL. Assuming you are
using MSSQL, there are functions like CHARINDEX() and PATINDEX(), but if you
have a lot of text in one column, then you should look also at full text
indexing (see Books Online).

As a side comment, it's not clear from your example what the data is, but
delimited text in a single column is often a sign of an incorrect data
model. You might want to review the model, and see if you can store only one
word in each column, which would make normal indexes much more effective.
But this may not apply, since your real data may look totally different.

Simon
Jul 20 '05 #3
hi simon,

PATINDEX is a very good usage for what I want. I just wonder about the
performance on a SQLSVR.
[a] delimited text in a single column is often a sign of an incorrect data
model. You might want to review the model, and see if you can store only
one word in each column, which would make normal indexes much more
effective.


that would make the query very oversized when using OR's and AND's: like
where (col1='apple' and col2='banana') or (col1='banana' and col2='apple')
and this is only a 2-words example.

greg
Jul 20 '05 #4
hi Muhd,

thanx for this very good and detailled example (i also make it very detailed
when I answer on quests).
a dictionary-table (Food_Attributes) makes it also very lean and a good
data-model.(->simon).

greg
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: todd | last post by:
here is a search tool SP I wrote. How many times have you wanted to search all your Stored procs or views (in a database) for a keyword but couldn't!? Well now you can! THis can makes life a...
2
by: Zambo via SQLMonster.com | last post by:
Hi! We have Sql Server 2000 in our server (NT 4). Our database have now about +350.000 rows with information of images. Table have lot of columns including information about image name, keywords,...
60
by: Julie | last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB) for a given string. The files are unindexed and unsorted, and for the purposes of my immediate requirements, can't...
3
by: vonclausowitz | last post by:
Hi All, I was thinking of creating a table in my database to index all words in the database. That way I can quickly search for one or more words and the index table will return the words and...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
5
by: Mark | last post by:
Hi I have an application (in vb.NET 2005) which holds data in SQL Server and some of the SQL records are simply paths to related files. I would like to be able to do a text search on both the...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
3
by: bluez | last post by:
I want to design a webpage where user can search the data from the database and list out the related records. Each of the record got a delete button which allow user to delete the record. ...
6
by: shantanu | last post by:
Hi All, I have a requirement to develop a search engine based on some search criteria that will search for the string or statement in all the documents uploaded in the website. The search result...
1
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.