2011-01-01 9 views
1

in der folgenden Tabelle würde ich wollen, dass die property_id eindeutig sein, so dass es keine doppelten Werte hat. Wie lautet die Syntax dafür?Wie stelle ich sicher, dass der Wert in einer Tabellenentität in mysql nicht wiederholt wird?

CREATE TABLE IF NOT EXISTS `propFeatures` (
`id` bigint(20) NOT NULL auto_increment, 
`bedroom` int(10) NOT NULL, 
`bathroom` int(10) NOT NULL, 
`balcony` int(10) NOT NULL, 
`furnished` tinyint(1) NOT NULL, 
`property_id` int(10) NOT NULL, 
PRIMARY KEY  (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

Antwort

1

Sie können UNIQUE Einschränkung Ihre property_id Spalte hinzufügen, so dass es Duplikate nicht zulässt, wenn Sie möchten.


Duplikate zu überprüfen, Sie diese Abfrage ausführen können:

select property_id, count(property_id) as total from propFeatures 
     group by property_id having count(property_id) > 1 

Wenn Sie Duplikate entfernen möchten, prüfen Sie mehr Informationen zu diesem Beitrag aus:

MySQL: Remove Duplicate Rows/Records from Table

Verwandte Themen