Ms SQL
壹、認識資料庫
資料庫的階層是有循序的關係,也就是由小到大的排列,其最小的單位是
Bit(位元),而最大的單位則是 Data Base(資料庫)。資料依其單位的大小與
相互關係的層次如下:
Bit(位元) → Byte(字元) → Field(資料欄) → Record(資料錄) → Table(資料表)
→ Data Base(資料庫)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
貳、主鍵( Primary Key )、外鍵( Foreign Key )
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
動腦時間 Q1
如果我想知道這個BusinessEntityID,這個員工曾經待過的部門(DepartmentID),以及他的名字(FirstName),那麼需要用到哪兩個表,這兩個表之間又是用什麼欄位產生關連的呢?
-
Ans 1
在 HumanResources.EmployeeDepartmentHistory 可以知道該員工曾經待過的部門 DepartmentID,而
Person.Person可以知道員工的名字。兩個資料表可以透過就 BusinessEntityID 欄位做合併。
(註解:如果需要知道部門 DepartmentID 的名字,可以用HumanResources.
Department 資料表做關聯。)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
參、SQL 資料庫結構
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
肆、SQL資料檔案類型-正規化(Normalization)
正規化的精神就是讓資料庫中重複的欄位資料減到最少,並且能快速的找到資料,以提高關聯性資料庫的效能。
- 正規化的目的 :
- 降低資料的重複性( Data Redundancy) (Data Redundancy)。
- 避免資料更新異常
參考資料:https://hackmd.io/@TSMI_E7ORNeP8YBbWm-lFA/rykcj8kmM?type=view
伍、SQL 資料型別
1. 浮點數
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
2. Unicode 字串
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
3. 其他
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
陸、SQL 語法
SELECT 查詢 - 欄位名稱
INTO 表名
FROM 從…來 - 表名
WHERE 在哪裡 - 條件敘述
GROUP BY 查詢 - 欄位名稱 (此查詢方法會指定兩個以上的欄位,且所有欄位值皆要符合相同資料才會被分為同一組)
ORDER BY 查詢 - 欄位名稱 ( 將 SELECT 取得的資料集依某欄位來作排序 )
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 查詢資料庫
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 建立資料庫
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
柒、MVC 架構
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
捌、SQL 指令
-
DDL (Data Definition Language) 資料定義語言用作開新資料表、設定欄位、刪除資料表、刪除欄位,管理所有有關資料庫結構的東西,常見的指令有
- Create:建立資料庫的物件。
- Alter:變更資料庫的物件。
- Drop:刪除資料庫的物件。
-
DML (Data Manipulation Language) 資料操作語言用作新增一筆資料,刪除、更新等工作,常見的指令有
- Insert:新增資料到 Table 中。
- Update:更改 Table 中的資料。
- Delete:刪除 Table 中的資料。
-
DQL (Data Query Language) 資料查詢語言只能取回查詢結果,指令只有1個
- Select:選取資料庫中的資料。
-
DCL (Data Control Language) 資料控制語言用作處理資料庫權限及安全設定,常見的指令有
- Grant:賦予使用者使用物件的權限。
- Revoke:取消使用者使用物件的權限。
- Commit:Transaction 正常作業完成。
- Rollback:Transaction 作業異常,異動的資料回復到 Transaction 開始的狀態

玖、關聯式資料庫模型

