Solved

Keeping database Record Order

Posted on 2010-09-23
5
646 Views
Last Modified: 2013-11-13
Note:Doing this in  MySQL

I'm trying to determine the best possible way to keep order of information in a database.  I'd like to keep connections between certain records.  For example:

I have 2 major tables: tblWords, tblSentences

tblWords
----------
id  INT
Word   VARCHAR(50)

if I typed a paragraph and found the id of each word in the tblWords, what would be the best way to organize a tblSentences table to store these sentences in order.

Say the sentence is: "I love cats and dogs" and the corresponding ids are [6] [29] [101] [2] [102].
How could i best form this sentence into a table.  I haven't quite determined if I should use some form of linker table for a many-to-many relationship or not and have the each sentence have an separate id.

The same sentence can be repeated multiple times.  I would maybe even like to add a paragraph table to keep order of sentences and so on.

Any suggestions?

Also, when trying to recall this information, how could you easily recall the information in the same easily based on the technique you suggest?

Thanks
0
Comment
Question by:Jcouls29
  • 3
5 Comments
 
LVL 40

Expert Comment

by:Sharath
Comment Utility
I did not get you exactly. Do you have words in tblWords table and want to insert sentences into tblSentences or vice versa? Can you elaborate more?
0
 
LVL 2

Author Comment

by:Jcouls29
Comment Utility
I want to put a sentences into a database.  I want to be able to separate them by words.  So each word is unique in tblWords.  How could I keep track of a sentence of words?

If I type,

"I have a good job"

into a program, I'll first separate the sentence and find the words in the database.  Then I need to somehow keep track of the order of the words so that I can recall the sentence again.  I'm looking for a structure of the database right now.  What's an optimal "sentence" table to be able to do this?

Should I have an order column and label the words 1,2,3,4,5,etc.  or is there a better way?

I hope this helps
0
 
LVL 16

Accepted Solution

by:
DrNikon224 earned 250 total points
Comment Utility
Can you make a third table? The best solution is to build a solution with three tables.

tblWords:
id int
word varchar(x)

tblSentences:
id int
label varchar(x)

tblOrder:
id int
sentenceID int
wordID int
order int

Put your words in the words table, create a record in the sentence table, then insert records into the Order table with the appropriate information. Then you can rebuild the sentence using the id from the sentence table and joining to the words and order table.
0
 
LVL 2

Author Comment

by:Jcouls29
Comment Utility
Is there a way to autonumber the 'Order' column so that I only have to define a word to add to a particular sentence id?

For example:
INSERT INTO tblOrder SET WordID = 20 WHERE SentenceID = 16     'Order = 0
INSERT INTO tblOrder SET WordID = 41 WHERE SentenceID = 16     'Order = 1
etc...

If I was to start a new sentence...
INSERT INTO tblOrder SET WordID = 89 WHERE SentenceID = 17      'Order = 0
...

I'd like Order to be done in the database.  It poses less of a chance for errors.
I like your method but I want to be sure I can implement it easily.  Thanks
0
 
LVL 2

Author Closing Comment

by:Jcouls29
Comment Utility
More implementation details would have helped.  But thanks for the help up to that point
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now