第35天~PK 及 FK~

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

PK 及 FK~

从资料表来看-
https://ithelp.ithome.com.tw/upload/images/20220207/201190352y0EF3hbaR.png

来写资料库的专有名词:
/images/emoticon/emoticon06.gif

值组-是以1条为单位=>这里是4笔
https://ithelp.ithome.com.tw/upload/images/20220207/20119035oMjJlkZg5x.png

关联-要有"唯一"..不用考虑顺序
https://ithelp.ithome.com.tw/upload/images/20220207/201190352rKh7SKP47.png

属性-栏位名称.不能重复
https://ithelp.ithome.com.tw/upload/images/20220207/20119035rq3SZF40O4.png

值域--就是资料类型-开始建资料库就要建好
/images/emoticon/emoticon04.gif

https://codingboy.pixnet.net/blog/post/26919164

https://ithelp.ithome.com.tw/upload/images/20220207/20119035pYTeMjUoIj.png

主键--这里不会有重复的学号

https://ithelp.ithome.com.tw/upload/images/20220207/20119035bgkjGDtlWh.png

单元值--一个格子只能放一笔资料

NULL 空值--跟"空格"不同

https://ithelp.ithome.com.tw/upload/images/20220207/20119035PwXGa8iUzH.png


开始建资料表-

https://ithelp.ithome.com.tw/upload/images/20220207/20119035WaPPW5nt3D.png

如果出来没有像这样一格..就开起来重开SQL

https://ithelp.ithome.com.tw/upload/images/20220207/201190359dHygjmOMi.png

要打成的目标:

https://ithelp.ithome.com.tw/upload/images/20220207/20119035K7XNGT3qis.png

开始打-资料类型用打得比用选得快

允许NULL就是允许空值

中文是一个字占2个位元组

char(10)就是5个中文字
varchar(50)就是25个中文字

英文是一个字占1个位元组

varchar(50)=var可变的位元型态=可以有50个位元组

建好之後 存档--资料库--叫"学生"--存档
https://ithelp.ithome.com.tw/upload/images/20220207/201190351w754uL3AU.png
左上--存档
https://ithelp.ithome.com.tw/upload/images/20220207/20119035xPdJTbyAEz.png

资料表名称--

https://ithelp.ithome.com.tw/upload/images/20220207/20119035j8ZeCtYwPd.png

从旁边展开-

https://ithelp.ithome.com.tw/upload/images/20220207/20119035YJ2MuRQVkI.png

用语法输入

对着"资料库"--右键--新增查询

https://ithelp.ithome.com.tw/upload/images/20220207/20119035a7A1Lu28I1.png

然後长这样-要确认是在要的资料库
https://ithelp.ithome.com.tw/upload/images/20220207/20119035kLWUdBEQ3P.png

找到要编写的资料表--按右键--编写资料表的指令码为--

https://ithelp.ithome.com.tw/upload/images/20220207/20119035FWso5N8a3s.png

这里选INSERT--新增查询编辑视窗
https://ithelp.ithome.com.tw/upload/images/20220207/20119035Awmiwzrn5X.png

出现范本-是无法执行的...

https://ithelp.ithome.com.tw/upload/images/20220207/20119035UROmVkSdEL.png

要打也是可以要按

https://ithelp.ithome.com.tw/upload/images/20220207/20119035YKhBTjxXrd.png

然後除了学号之外其他都要加入"单引号"就是' '(要自己打)

https://ithelp.ithome.com.tw/upload/images/20220207/20119035edrh4xA1no.png

长得像这样

https://ithelp.ithome.com.tw/upload/images/20220207/20119035rR7WRTedrm.png

确认後变

https://ithelp.ithome.com.tw/upload/images/20220207/20119035L5Z7D8eXq9.png

太慢了~直接用KEY的

https://ithelp.ithome.com.tw/upload/images/20220207/20119035LbJouNrsUj.png

现在长这样
https://ithelp.ithome.com.tw/upload/images/20220207/20119035TD7d7IBscO.png

KEY values() +复制贴上TXT档

https://ithelp.ithome.com.tw/upload/images/20220207/2011903543hjw8zwID.png

+复制贴上TXT档+要加入"单引号"就是' '(要自己打)

https://ithelp.ithome.com.tw/upload/images/20220207/20119035c5pll3slMU.png

选起来後按"执行"

https://ithelp.ithome.com.tw/upload/images/20220207/20119035OJGnn010PQ.png

然後新增
https://ithelp.ithome.com.tw/upload/images/20220207/20119035gLV44M5j3U.png

/images/emoticon/emoticon02.gif


再来是"找资料"-

select *
from [dbo].[学生]
where[学号]=1


https://ithelp.ithome.com.tw/upload/images/20220207/20119035g208p0Q3K8.png

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


<<:  第34天~还原资料库完.然後~

>>:  终端执行py.ipynb档

Day14. Module & #extend #prepend #include - Ruby 继承 part1

Day14-15 一共会介绍 Ruby的2类、4种继承方式。 在Day2 我们提到 Ruby 为单一...

Day01 序 -- 大致安好

特别的一年,从每天上班战战兢兢的通勤上班,到经历过长时间的家工作 不知道大家有没有不习惯的感觉呢? ...

Python - 费式数列之呼吸

费式数列 (引用至维基面科) 斐波那契数列(义大利语:Successione di Fibonacc...

Day4:进入新手村前先让我复习一下QQ-CSS3-Flexbox-基本用途

Flexbox是CSS3的盒模型,这个属性是用来做排版使用,也因为它可以灵活弹性排版的特性,也很常使...

【Day2】声音的一些基本介绍

声音这东西实在是太自然了,所以我们很少去思考这东西的本质到底是什麽 简单的来复习一下声音是什麽,你...