demo
如何為MySQL中的多列指定唯一約束?
MySQL SQL Server 拉丁的傳說 2019-06-03 10:25:56
如何為MySQL中的多列指定唯一約束?
我有張桌子:
table votes (
id,
user,
email,
address,
primary key(id),);
現在我想讓列用戶,電子郵件,地址獨一無二的(一起)
如何在MySQL中做到這一點?
當然這個例子就是.。舉個例子。所以請不要擔心語義學。
create table user_actions (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增ID',
`passport_uid` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '用戶passport_uid',
`cuid` varchar(128) NOT NULL DEFAULT '' COMMENT 'cuid',
`buss_id` bigint(20) unsigned NOT NULL DEFAULT '' COMMENT '店鋪ID',
`uc_id` bigint(20) unsigned NOT NULL DEFAULT '' COMMENT 'ucid',
`action_type` tinyint(4) unsigned NOT NULL DEFAULT 1 COMMENT '1、頁面瀏覽 2、留言咨詢 3、撥打電話',
`action_info` varchar(1024) NOT NULL DEFAULT '' COMMENT '行為內容,如頁面瀏覽的地址',
`create_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '創建時間',
`update_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '更新時間',
primary key (`id`),
key `k_ucid` (`uc_id`),
key `k_bussid` (`buss_id`),
unique key `uk_uid_bussid_type` (`passport_uid`, `buss_id`, `action_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用戶行為表';