我有一个tablekey name id location
10 aa a1 east
12 b a2 east
10 aa a1 west
....
其中的三列:key name id,在location 确定的情况下,每一列都不能重复出现,否则程序查询出数据后,运行出错怎样做下限制,在insert数据时,同一个location下,当前三列中,某一列出现重复时,insert失败比如
key name id location
10 aa a1 east
10 b a2 east
east中,key重复,不允许
key name id location
10 aa a1 east
10 b a2 west
location不同,key重复可以
10 aa a1 east
12 b a2 east
10 aa a1 west
....
其中的三列:key name id,在location 确定的情况下,每一列都不能重复出现,否则程序查询出数据后,运行出错怎样做下限制,在insert数据时,同一个location下,当前三列中,某一列出现重复时,insert失败比如
key name id location
10 aa a1 east
10 b a2 east
east中,key重复,不允许
key name id location
10 aa a1 east
10 b a2 west
location不同,key重复可以
create unique index i1 on table名(key, location);
create unique index i2 on table名(name, location);
create unique index i3 on table名(id, location);