ยินดีต้อนรับ

SQL Server เบื้องต้น

John MacKintosh

Instructor

shutterstock_1255111450.jpg

shutterstock_418087330.jpg

SQL Server เบื้องต้น

SQL Server & Transact-SQL

  • SQL Server - ระบบฐานข้อมูลเชิงสัมพันธ์ที่พัฒนาโดย Microsoft

  • Transact-SQL (T-SQL) - การนำ SQL ไปใช้งานของ Microsoft พร้อมฟังก์ชันเพิ่มเติม

  • ในคอร์สนี้: เรียนรู้พื้นฐาน T-SQL อย่างแม่นยำ

  • เรียนเขียนคิวรี

SQL Server เบื้องต้น

shutterstock_274642010.jpg

SQL Server เบื้องต้น

การเขียนคิวรีเบื้องต้น

  • SQL Server: คลังข้อมูลที่เก็บฐานข้อมูลและตาราง

  • คิวรี: วิธีเลือกข้อมูลจากส่วนต่าง ๆ และนำมาใช้งาน

  • SELECT: คำสำคัญสำหรับดึงข้อมูล

SQL Server เบื้องต้น
SELECT description 
FROM grid;
+-------------------------------------+
| description                         |
|-------------------------------------|
| Severe Weather Thunderstorms        |
| Severe Weather Thunderstorms        |
| Severe Weather Thunderstorms        |
| Fuel Supply Emergency Coal          |
| Physical Attack Vandalism           |
| Physical Attack Vandalism           |
| Physical Attack Vandalism           |
| Severe Weather Thunderstorms        |
| Severe Weather Thunderstorms        |
| Suspected Physical Attack           |
| Physical Attack Vandalism           |
| ...                                 |
+-------------------------------------+
SQL Server เบื้องต้น

การเลือกมากกว่าหนึ่งคอลัมน์

SELECT 
  artist_id, 
  artist_name 
FROM 
  artist;
+-----------+----------------------+
| artist_id | artist_name          |
|-----------+----------------------|
| 1         | AC/DC                |
| 2         | Accept               |
| 3         | Aerosmith            |
| 4         | Alanis Morissette    |
| 5         | Alice In Chains      |
| 6         | Antônio Carlos Jobim |
| 7         | Apocalyptica         |
| 8         | Audioslave           |
| 9         | BackBeat             |
| 10        | Billy Cobham         |
+-----------+----------------------+
SQL Server เบื้องต้น

การจัดรูปแบบคิวรี

SELECT description, event_year, event_date
FROM grid;
SELECT 
  description, 
  event_year, 
  event_date
FROM 
  grid;
SQL Server เบื้องต้น

Select TOP()

-- Return 5 rows
SELECT TOP(5) artist
FROM artists;
-- Return top 5% of rows
SELECT TOP(5) PERCENT artist 
FROM artists;
+-----------------------+
| artist                |
|-----------------------|
| AC/DC                 |
| Accept                |
| Aerosmith             |
| Alanis Morissette     |
| Alice in Chains       |
+-----------------------+
SQL Server เบื้องต้น

Select DISTINCT

-- Return all rows in the table
SELECT nerc_region 
FROM grid;
+-------------+
| nerc_region |
|-------------|
| RFC         |
| RFC         |
| MRO         |
| MRO         |
| ....        |
+-------------+
-- Return unique rows
SELECT DISTINCT nerc_region 
FROM grid;
+-------------+
| nerc_region |
|-------------|
| NPCC        |
| NPCC RFC    |
| RFC         |
| ERCOT       |
| ...         | 
+-------------+
SQL Server เบื้องต้น

Select *

-- Return all rows
SELECT * 
FROM grid;
  • ไม่เหมาะสำหรับตารางขนาดใหญ่
SQL Server เบื้องต้น

การตั้งชื่อแทนคอลัมน์ด้วย AS

SELECT demand_loss_mw AS lost_demand 
FROM grid;
+-------------+
| lost_demand |
|-------------|
| 424         |
| 217         |
| 494         |
| 338         |
| 3900        |
| 3300        |
+-------------+
SELECT description AS cause_of_outage 
FROM grid;
+------------------------------+
| cause_of_outage              |
|------------------------------|
| Severe Weather Thunderstorms |
| Fuel Supply Emergency Coal   |
| Physical Attack Vandalism    |
| Suspected Physical Attack    |
| Electrical System Islanding  |
+------------------------------+
SQL Server เบื้องต้น

มาฝึกเขียน T-SQL กันเถอะ!

SQL Server เบื้องต้น

Preparing Video For Download...