Question How do I prevent duplicate entry into SQL database?

stresss

Member
Joined
Aug 11, 2008
Messages
21
Programming Experience
Beginner
Hi there! I am trying to prevent duplicate Message Lines from being entered into my SQL database table. The data being entered is not a primary key in my database table and it's a message. So how do I prevent duplicate messages in my database? Do I use datareader? Your help is badly needed! :).
 
I suggest u desing a new table for the messages and links it to the table where u dont want the data to be repeat. Be careful, it could be messages that seem the same, but dont have the same text.
 
Hmmm.. it sounds like a good way but how am i supposed to do it? Set it as primary key in the other table and set it as foreign key in the original table? is this how i link it? Sorry for the trouble! :)
 
yes, that the way it must be done. It is called data integrity. The only problem is that on the messages table the user could enter 2 diferent messages than meaning the same. I suggest u that full that table with all the possible messages (if that is possible) and ur problem will be solved

good luck
 
okay, I have this windows form which is to create messages and store all the data into the database table. I have a MsgID field as my primary key already, Message Field and other fields. I have a Textbox for the user to type the message, so how do I prevent duplicate messages from being entered into the SQL database table? :). Your help will be much appreciated!.
 
u got a big problem pal.If the text of the new message exists previously (make a search by the field messahe field), u can not add the new one message. The problem is that the previous message can be "Missing data" and the second could be "you need enter more data", both of them means the same. One more character and the message will be diferent at the time of compare them. The only way to solve this is adding the all possible message by your own or when the user is going to enter a new message, list all the existing message for him to select one of them and that way, u could help that existing on the table some differente messages meaning the same. U could also check often the system and change all the messages that means the same. Let de user do the less possible. They dont understand programs and most of time behave as silly.
 
okay, I have this windows form which is to create messages and store all the data into the database table. I have a MsgID field as my primary key already, Message Field and other fields. I have a Textbox for the user to type the message, so how do I prevent duplicate messages from being entered into the SQL database table? :). Your help will be much appreciated!.

By having someone who is not an idiot program all the messages, and only allowing the idiot users to read them, not create their own.

Bear in mind that eventually, your system will fall into the hands of an idiot, disguised as a manager, and then it's all to pot.. But you can try!


ps; the simplest way to prevent identical message texts being entered is to create a unique index on the message text
 
Back
Top