Day1 : Course Overview [SUT Coding for All #5 Basic Data Server]
2 min readJun 24, 2018
--
Table of Contents
- Basic SQL (SQLite, MySQL, Postgres)
- Introduction to MongoDB
- Mongo Shell
1. Basic SQL
SQL ย่อมาจาก structured query language คือภาษาที่ใช้ในการเขียนโปรแกรม เพื่อจัดการกับฐานข้อมูลโดยเฉพาะ
- Create Table การสร้างตาราง
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
);CREATE TABLE students (
id int,
name varchar(255),
age int
);
- Query การดึงข้อมูล
SELECT column1, column2, …
FROM table_name;SELECT * FROM table_name;
- Query (Condition) การดึงข้อมูลแบบมีเงื่อนไข
SELECT column1, column2, …
FROM table_name
WHERE condition;SELECT * FROM students
WHERE name ='Tanapon';SELECT * FROM students
WHERE age = 20;
- Insert Table การเพิ่มข้อมูล
INSERT INTO table_name (column1, column2, column3, …)
VALUES (value1, value2, value3, …);INSERT INTO students (id, name, age)
VALUES (1 , 'Tanapon Kongjaroensuk', 21);
- Update Table การแก้ไขข้อมูล
UPDATE table_name
SET column1 = value1, column2 = value2, …
WHERE condition;UPDATE students
SET age = 20
WHERE name = 'Tanapon Kongjaroensuk';
*หากไม่บอกว่า update ที่ไหนมันจะทำการ update ทั้งตาราง อย่าลืม WHERE
- Delete Table การลบข้อมูล
DELETE FROM table_name
WHERE condition;DELETE FROM students
WHERE name ='Tanapon Kongjaroensuk';
- Example
เว็บสำหรับลองเล่น SQL ง่ายๆไม่ต้องติดตั้งบนเครื่อง