Table Structure
FIELD TYPE COLLATION NULL KEY DEFAULT Extra PRIVILEGES COMMENT------------- ------------ -------------- ------ ------ ------- -------------- -------------------- -------id BIGINT(20) (NULL) NO PRI (NULL) AUTO_INCREMENT SELECT,INSERT,UPDATE resource_name VARCHAR(128) gbk_chinese_ci YES (NULL) SELECT,INSERT,UPDATE resource_type TINYINT(4) (NULL) YES (NULL) SELECT,INSERT,UPDATE
Add a unique constraint for resource_name and resource_type
ALTER TABLE jw_resourceADD UNIQUE KEY(resource_name, resource_type);
Result: Show create table resource_resource;
CREATE TABLE `jw_resource` ( `id` BIGINT(20) NOT NULL AUTO_INCREMENT, `resource_name` VARCHAR(128) DEFAULT NULL, `resource_type` TINYINT(4) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `resource_name` (`resource_name`,`resource_type`)) ENGINE=INNODB AUTO_INCREMENT=2 DEFAULT CHARSET=gbk