有没有办法使整个MySQL行唯一 [英] Is there a way to make an entire MySQL row unique

查看:96
本文介绍了有没有办法使整个MySQL行唯一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySQL中有一个表,其中包含30列和数千个条目.
有没有一种方法可以使每一行都唯一,这意味着如果某行已经存在,则我将无法再次输入该行.

I have a table in MySQL with 30 columns and thousands of entries.
Is there a way I could make every row unique, that means if a row already exists, I should not be able to enter that row again.

在这里我不能使用主键或唯一键,因为每个列都可能会重复.
我希望该行是唯一的. 例如:-有一个带有

I can't use primary or unique keys here, because individually every column might be repeated.
I want the row to be unique. for example:-There are is a table with

columns->name,age,height,weight.

在此列中,我不能使任何一列或两列都是唯一的,但我不应有两个条目具有相同的数据.

In this column I can't make any one or two columns unique but I should not have two entries with all the same data.

推荐答案

您需要一个复合主键.

复合主键告诉MySQL您希望主键是字段的组合.

A composite primary key tells MySQL that you want your primary key to be a combination of fields.

更多信息在这里: 为什么使用多列作为主键(复合主键)

这篇关于有没有办法使整个MySQL行唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆