第37天~两张资料表之间

这篇的上一篇:https://ithelp.ithome.com.tw/articles/10283916

超键、候选键、主键、外来键、联合主键、复合主键

/images/emoticon/emoticon04.gif

https://www.itread01.com/content/1545892442.html

写得很好~

https://blog.kkbruce.net/2010/10/normalization-key.html#.YgGcN7pBxPY


https://ithelp.ithome.com.tw/upload/images/20220208/20119035laZKsJeocm.png

主键的挑选顺序:超键、候选键、主键、替代键

超键-唯一性.不允许两个值相同.表格看不到

n 一律不会定义可储存的字元数。 这类似於 CHAR (n) 和 VARCHAR (n) 的定义。

固定大小 nchar 或变动大小 nvarchar 的字元资料类型

在资料库语法前面要加[表格名]=N'字串'

除了数字之外.'字串' 都要加' '


候选键-唯一性

主键-唯一性/不允许空值/-单一资料表-PK-Primary Key

外来键(外部索引键)-Foreign Key,FK-多重资料表


TSQL开发图表工具-两个档案直接放C槽(不要放桌面)
https://ithelp.ithome.com.tw/upload/images/20220208/201190358m74Y5TnAu.png

https://ithelp.ithome.com.tw/upload/images/20220208/20119035MvCONsiLfk.png

画图~ERD

https://ithelp.ithome.com.tw/upload/images/20220208/20119035E8TNln15Nh.png

打开长这样

https://ithelp.ithome.com.tw/upload/images/20220208/20119035BEqtItmyR6.png

选-->其他工作表-->ER

https://ithelp.ithome.com.tw/upload/images/20220208/20119035CpTNJigoXO.png

主要选这三个图-

https://ithelp.ithome.com.tw/upload/images/20220208/20119035SeQdkYMjMD.png

传统ERD SOP:

  1. 实体--资料表
  2. 关系(联)-->FK-->PK
  3. 属性-->资料行(栏位)
    4.资料库设计步骤

https://ithelp.ithome.com.tw/upload/images/20220208/20119035TYWcuBopv2.png

开始~

  1. 实体--资料表

https://ithelp.ithome.com.tw/upload/images/20220208/20119035QS4DaUaBHu.png

编辑名称-确定

https://ithelp.ithome.com.tw/upload/images/20220208/20119035RHoZePH84c.png

长这样
https://ithelp.ithome.com.tw/upload/images/20220208/20119035WoNFO5PNtu.png

  1. 关系(联)-->FK-->PK

https://ithelp.ithome.com.tw/upload/images/20220208/20119035AP2G8sdMYt.png

修改内容+1+N代表很多(从以前大家都这样做)-确定-->按CTRL+滚轮就是放大

https://ithelp.ithome.com.tw/upload/images/20220208/20119035F67D2iUFUn.png

准备画线

https://ithelp.ithome.com.tw/upload/images/20220208/20119035Hi0Y2J95VF.png
把下面3个都变成-直线
https://ithelp.ithome.com.tw/upload/images/20220208/20119035k3pCN4cDYt.png

按住开始画直线
https://ithelp.ithome.com.tw/upload/images/20220208/20119035uU8yUEzQJh.png
结果长这样
https://ithelp.ithome.com.tw/upload/images/20220208/20119035KIAq2qihDP.png

  1. 属性-->资料行(栏位)

https://ithelp.ithome.com.tw/upload/images/20220208/20119035AJmGxQqfvC.png

放好(用ctrl+C-->ctrl+V)

https://ithelp.ithome.com.tw/upload/images/20220208/20119035pqU3GRacck.png
-画好线

https://ithelp.ithome.com.tw/upload/images/20220208/2011903563IUwKxruZ.png

点开--键值选"是"

https://ithelp.ithome.com.tw/upload/images/20220208/20119035HEeAtd7HZT.png

出现底线- 没有底线=键值选"否"

https://ithelp.ithome.com.tw/upload/images/20220208/201190350TrJXIKDgv.png

画好-存档--取名称--存档

https://ithelp.ithome.com.tw/upload/images/20220208/201190356cls5WdP7f.png


成果-https://ithelp.ithome.com.tw/upload/images/20220208/20119035KrlWQ80XvY.png


换工具来做-下载

https://ithelp.ithome.com.tw/upload/images/20220208/20119035Ve2HZqEIfd.png
从开始来打开
https://ithelp.ithome.com.tw/upload/images/20220208/20119035eNHcjUQz5I.png

按CREAT

https://ithelp.ithome.com.tw/upload/images/20220208/20119035z8eTRGkcxr.png

按X
https://ithelp.ithome.com.tw/upload/images/20220208/20119035wuAQEuQH8V.png

准备开始画-

现代ERD SOP:

  1. 实体--资料表=table
  2. 属性-->资料行(栏位)=Column
  3. 关系(联)-->FK-->PK

  1. 实体--资料表=table

右键-table--改第一格变"课程"

https://ithelp.ithome.com.tw/upload/images/20220208/20119035BTKs2GSLnM.png

改第一格变"课程"
https://ithelp.ithome.com.tw/upload/images/20220208/20119035njE79fAqA1.png

长这样
https://ithelp.ithome.com.tw/upload/images/20220208/20119035h4x945IDM3.png

右上+放大镜放大

新增栏位-
https://ithelp.ithome.com.tw/upload/images/20220208/20119035bqMWE8vhm4.png
主键V
https://ithelp.ithome.com.tw/upload/images/20220208/20119035qL3xqnVhNJ.png

选择TYPE-数字用INT
--不可以空值
https://ithelp.ithome.com.tw/upload/images/20220208/20119035euicc88Orq.png
长这样
https://ithelp.ithome.com.tw/upload/images/20220208/20119035Xj00SQPPT1.png

继续上面步骤--只是是要放中文字--要选VARCHAR--20

https://ithelp.ithome.com.tw/upload/images/20220208/201190356y1Ff54pqb.png

错了~点2下可以再进去改

下面依序做

https://ithelp.ithome.com.tw/upload/images/20220208/20119035LCU89dd4XV.png

现在长这样

https://ithelp.ithome.com.tw/upload/images/20220208/20119035RsOt6cSeDh.png

再把另外一个表也盖好

https://ithelp.ithome.com.tw/upload/images/20220208/20119035CUeCf8HRG4.png

画关系线:

https://ithelp.ithome.com.tw/upload/images/20220208/20119035MPAMZyzhai.png

按虚线-要先选"课程"--再选"测验"-->就是"一对多"

https://ithelp.ithome.com.tw/upload/images/20220208/20119035XEq69TSaRW.png

然後存档

https://ithelp.ithome.com.tw/upload/images/20220208/20119035M6XzukshBA.png

最後长这样

https://ithelp.ithome.com.tw/upload/images/20220208/20119035auZEzqaYv6.png


产生语法:
按SQL图案-

https://ithelp.ithome.com.tw/upload/images/20220208/20119035B0eMk7or6k.png

  1. 属性-->资料行(栏位)=Column
  2. 关系(联)-->FK-->PK

这篇的下一篇:https://ithelp.ithome.com.tw/articles/10283923


<<:  第36天~就是自己KEY

>>:  ISO 27001 资讯安全管理系统 【解析】(二)

【在厨房想30天的演算法】Day 01 演算法好吃吗~

【在厨房想30天的演算法】Day 01 演算法好吃吗~ Aloha!我是少女人妻Uerica!哈哈...

[day7]呼叫永丰API及流程串接整理

今天先来进行呼叫永丰API 串接永丰API 按照范例测试,主要针对建立订单进行实作,查询订单等API...

EP12 - 重构并模组化 Terraform 程序码

传统的架构上, 我们会使用独立机械建置 Git、Jenkins, 最後部署至目标环境, 到目前为止,...

Day 16 : 模型衡量指标

由於我们需要有指标来衡量一个模型的好坏,而问题可以粗略分成「分类」和「回归」问题。而根据不同的问题,...

Day13 SwiftUI 06 - WebView

接下来我们来看看在SwiftUI 怎麽使用WebView 网页的元件,SwiftUI 框架 有一个缺...