背景:一对一关系设计方法:

设计2张表:customer表,student表

学生表中通过字段customer_id与customer表产生关系。

student表中的customer_id与customer表中的id值(主键)应当是一对一的关系。

所以在student表中要保证customer_id值是唯一的。

2张表的表结构如下:

左表的一条记录唯一对应右表的一条记录,反之也一样

create table customer(
id int primary key auto_increment,
name char(20) not null,
qq char(10) not null,
phone char(16) not null
); create table student(
id int primary key auto_increment,
class_name char(20) not null,
customer_id int unique, #该字段一定要是唯一的
foreign key(customer_id) references customer(id) #此时外键的字段一定要保证unique
on delete cascade
on update cascade );

通过navicat设置表的某1个字段值为一,就是为该字段建立索引,索引类型选择UNIQUE

具体的操作步骤,参照:

Navicat Premium怎么设置字段的唯一性(UNIQUE)?

检查配置的结果:

当某1个字段的值被设置为唯一之后,如表中已经存在custome_id=1,当再次插入custome_id=1的记录时,就会报错

最新文章

  1. sqlyog导出json数据格式支持mysql数据转存mongodb
  2. PHP中多线程处理
  3. NodeJs+http+fs+request+cheerio 采集,保存数据,并在网页上展示(构建web服务器)
  4. 将博客搬至CSDN
  5. linux时间同步ntp服务的安装与配置
  6. C# GZip对字符串压缩和解压
  7. (zhuan) Deep Reinforcement Learning Papers
  8. python中的popen和subprocess
  9. 【BZOJ】【1015】 【JSOI2008】星球大战starwar
  10. error: format not a string literal and no format arguments [-Werror=format-security]
  11. Java基础知识强化之IO流笔记17:FileOutputStream构造方法使用
  12. hadoop2.5.2安装部署
  13. 从一个例子入门Mysql储存过程
  14. Salesforce的公式和验证规则
  15. JSESSIONID、SESSION、cookie .
  16. 算法 -- 四种方法获取的最长“回文串”,并对时间复杂进行分析对比&PHP
  17. 由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值。System.Threading.ThreadAbortException
  18. jms和activemq简介
  19. Ext BoxComponent
  20. javascript原型继承---constructor篇

热门文章

  1. easyUI解析原理
  2. markdown的日常使用
  3. JQuery高级笔记
  4. Linux目录的切换
  5. static静态和非静态详解
  6. dijkstra算法之优先队列优化
  7. 【NOIP2014模拟10.25A组】画矩形
  8. linux 配置内网yum源
  9. sqlserver 返回刚插入的那条数据
  10. BZOJ 4488: [Jsoi2015]最大公约数 暴力 + gcd