简体   繁体   English

在添加之前检查条目

[英]Checking the entry before adding it

I need help, I need a query that will check and will not allow adding a new entry as long as the value in the datanumber column does not repeat, but on the condition that the name is the same in the dataname column.我需要帮助,我需要一个查询来检查并且不允许添加新条目,只要 datanumber 列中的值不重复,但条件是 dataname 列中的名称相同。 Screen屏幕

Scenario: I am adding a new entry [dataname] [datanumber]:场景:我正在添加一个新条目 [dataname] [datanumber]:

  1. SENIOR |高级 | 3 - write 3 - 写
  2. WEB | WEB | 2 - write 2 - 写
  3. SENIOR |高级 | 2 - unable to write 2 - 无法写入
  4. ADMIN |管理员 | 2 - write 2 - 写
  5. ADMIN |管理员 | 2 - unable to write 2 - 无法写入

Solution below下面的解决方案

ALTER TABLE my_table_name 
ADD CONSTRAINT MyUniqueConstraint UNIQUE(dataname, datanumber)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM