On Wed, Jan 08, 2003 at 10:27:30AM -0800, Steven Nakhla wrote: > Aside from designating a row as a primary key, is > their any SQL syntax to force that entries within a > row are unique (such as a string value)? Thanks!
Hello Steve, You can create a UNIQUE key for a column that will ensure that all values entered into the column are unique. i.e. CREATE TABLE foo ( ..., ..., UNIQUE (...) ) If you truly want to ensure that a row is unique, then you can create a UNIQUE key that contains all of the columns in a table. This will allow you to enter duplicate values within the columns, but the combination of values (in this case, an entire row) must be unique. i.e. CREATE TABLE combolock ( tumbler_1 INT NOT NULL, tumbler_2 INT NOT NULL, tumbler_3 INT NOT NULL, UNIQUE tumblers (tumbler_1, tumbler_2, tumbler_3) ) mysql> INSERT INTO combolock VALUES (1,1,1); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO combolock VALUES (1,1,1); ERROR 1062: Duplicate entry '1-1-1' for key 1 mysql> INSERT INTO combolock VALUES (1,1,2); Query OK, 1 row affected (0.00 sec) Cheers! -- Zak Greant <[EMAIL PROTECTED]> | MySQL Advocate | http://zak.fooassociates.com Using and Managing MySQL MySQL Training: Stockholm, February 24-28, 2003 Visit http://mysql.com/training for more information "While we are postponing, life speeds by." --Lucius Annaeus Seneca --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php