SQL
呢篇文 需要熟悉呢方面嘅人幫手寫。 |
SQL(通常讀 /ˈsi:kwəl/,全名:Structured Query LanguageCategory:有英文嘅文章 )係用落數據庫度查數據嘅電腦語言。用 SQL 嘅數據庫管理系統主要係關係數據庫,比較出名嘅包括 MySQL、Oracle 等等,SQL 好早已經由國際標準化組織標準化,編號 ISO/IEC 9075,但係唔同系統嘅 SQL 喺格式上仍然有唔同。
基本概念
SQL 會用到嘅基本概念:
- 主匙
- 用嚟識別唔同記錄,每筆記錄嘅主匙都係獨一無二嘅。
查詢功能
SQL 最常見嘅用途,係用嚟查詢數據庫入便嘅數據,係噉咦整理下,再顯示出嚟畀用家睇[1]。
SQL 查詢(Query)嘅核心邏輯,可以簡化為三個步驟:首先由 FROM 指定去邊張表格度摷料;跟住用 WHERE 嚟做篩選,將唔符合條件嘅個案剔除;最後用 SELECT 決定要顯示邊幾行嘅特性,仲可以用 AS 幫啲欄位改個名,令輸出嘅結果更易睇。舉個例,
SELECT Name AS Meng2
FROM Students
WHERE Age > 20
呢段,係同電腦講:去學生(Students)嗰張表度(FROM),搵出 Age 數值大過 20 嘅個體(WHERE),然後將佢哋嘅 Name 顯示出嚟,並將之標註為 Meng2(名呢個詞嘅粵拼)。好似噉嘅流程,確保電腦可以精準噉喺成幾百萬行咁長數據嘅入便撈返啱用嘅嘢出嚟。
管控功能
- CREATE TABLE IF NOT EXISTS
- 用嚟製作新嘅表格,如果具有嗰個名嘅表格並唔存在。
- INSERT
- 用嚟新增資料行。
- UPDATE
- 用嚟修改已有資料。
保安問題
睇埋:SQL注入
喺電腦保安嗰度,SQL 注入係一種常見嘅攻擊手段,屬於代碼注入。攻擊者會喺輸入框插一啲惡意嘅 SQL 指令落去。從而攞到一啲佢哋唔應該攞到嘅數據[2]。
另見
引用
- Codd, Edgar F (June 1970). "A Relational Model of Data for Large Shared Data Banks". Communications of the ACM. 13 (6): 377–87. doi:10.1145/362384.362685. S2CID 207549016.
- C. J. Date with Hugh Darwen: A Guide to the SQL standard : a users guide to the standard database language SQL, 4th ed., Addison Wesley, USA 1997, ISBN 978-0-201-96426-4
引咗
- ↑ 🧠 SQL Query Execution Flow — Explained for Developers,佢哋呢度亦有講:"When writing a SQL query, we often write the clauses in the order: SELECT, FROM, WHERE, etc. But did you know SQL Server doesn’t execute them in that order?"
- ↑ Microsoft. "SQL Injection" (英文). 原先內容歸檔喺August 2, 2013. 喺2013-08-04搵到.
SQL injection is an attack in which malicious code is inserted into strings that are later passed to an instance of SQL Server for parsing and execution. Any procedure that constructs SQL statements should be reviewed for injection vulnerabilities because SQLi Server will execute all syntactically valid queries that it receives. Even parameterized data can be manipulated by a skilled and determined attacker.
Category:CS1英文語言來源 (en) - ↑ 可以睇:
sqlite3.connect - ↑ "sqlite3 — DB-API 2.0 interface for SQLite databases". The Python Standard Library Documentation.
註解
拎
- (英文)ISO/IEC 9075 嘅官方網頁
- (英文)SQL 教學