Re: Beginner question - Preventing Duplicate Entries
You could make the column a unique key...that would prevent duplicates from being entered. Then if you want to be able to try inserting duplicates (like if you don't want the query to fail on duplicate attempts), you could do INSERT IGNORE INTO myTable ... Check http://www.mysql.com/doc/en/CREATE_TABLE.html and http://www.mysql.com/doc/en/ALTER_TABLE.html for information about keys. -Brian McCain - Original Message - From: Wileynet [EMAIL PROTECTED] To: 'mysql users' [EMAIL PROTECTED] Sent: Wednesday, March 26, 2003 3:03 PM Subject: Beginner question - Preventing Duplicate Entries Is there a sql statement that would not allow the same entry twice. Something like INSERT into myTable s WHERE s != Value(?). I don't know if that makes sense but I thought I would give it a shot. Basically I want to know if it is possible and if so can you point me to a webpage or give me an example if you can? Thanks in advance - Wiley -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Beginner question - Preventing Duplicate Entries
Is there a sql statement that would not allow the same entry twice. Something like INSERT into myTable s WHERE s != Value(?). I dont know if that makes sense but I thought I would give it a shot. Basically I want to know if it is possible and if so can you point me to a webpage or give me an example if you can? Thanks in advance - Wiley -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
RE: Beginner question - Preventing Duplicate Entries
If you wanted to use MyISAM tables and peform an initial select to determine whether you should insert, you could lock the table you would be selecting/insert from. 'LOCK TABLES table_name WRITE' Don't forget to unlock the table when you are done 'UNLOCK TABLES', otherwise you will likely have deadlocks. ~Wynne -Original Message- From: Wileynet [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 26, 2003 2:04 PM To: 'mysql users' Subject: Beginner question - Preventing Duplicate Entries Is there a sql statement that would not allow the same entry twice. Something like INSERT into myTable s WHERE s != Value(?). I don't know if that makes sense but I thought I would give it a shot. Basically I want to know if it is possible and if so can you point me to a webpage or give me an example if you can? Thanks in advance - Wiley -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
RE: Beginner question - Preventing Duplicate Entries
Add a UNIQUE INDEX to the table you are inserting to. You will then get an error if you try to insert a second time with the same values. Alternativly you could use perform a select and then an insert within the same transaction, determining whether something exists in the db before inserting. This of course would require transactions supported by InnoDB tables and not supported by MyISAM. ~Wynne -Original Message- From: Wileynet [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 26, 2003 2:04 PM To: 'mysql users' Subject: Beginner question - Preventing Duplicate Entries Is there a sql statement that would not allow the same entry twice. Something like INSERT into myTable s WHERE s != Value(?). I don't know if that makes sense but I thought I would give it a shot. Basically I want to know if it is possible and if so can you point me to a webpage or give me an example if you can? Thanks in advance - Wiley -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]