Reputation: 25
can anyone help me to make a mysql table to prevent duplicate entries in 3 columns only?.
I have 5 columns as below id username email serverip dbport
I want to prevent duplicates only for id, email and serverip Also I want to make the id auto increment. Is it possible only with mysql?
Upvotes: 0
Views: 826
Reputation: 12618
You can add UNIQUE index for those fields, for example:
ALTER TABLE `your_schema`.`your_table` ADD UNIQUE INDEX `Index_Name`
(`your_column`);
Add same index for each column you want to be unique.
For setting column to autoincerment:
ALTER TABLE `your_schema`.`your_table` MODIFY COLUMN `column_name` INT(10)
UNSIGNED NOT NULL, MODIFY COLUMN `column_name` INT(10) UNSIGNED NOT NULL
AUTO_INCREMENT;
(Make sure that you use your datatypes)
Upvotes: 2