duai4512 2013-03-19 08:22
浏览 8

两个字段作为杂货Crud中的一个独特字段

I have one problem in GroceryCrud.

I want to insert the data in one table. Table is like this:

id, card_no, site_code, site_no

card_no is unique and i have implemented it.

However; my problem is that site_code and site_no should be unique only is both values match. Which means that is site_code is 101 and site_no is 102 and we try to insert identical values for both again is should reject it. If we one of the values is different it should allow it.

In this case we are treating both values as one when we insert it.

I hope I'am clear.

Thanks in advance.

  • 写回答

3条回答 默认 最新

  • dsfphczao23473056 2013-03-19 08:47
    关注

    It sounds like you should look over the constraints on your table.

    Is there a good reason for using an id column in this case? If there is not you should remove it and then set both site_code and site_no as your primary key.

    With (site_code,site_no) as your primary key yo will not be able to insert duplicates of those two values.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法