Hoş geldiniz

SQL Server'a Giriş

John MacKintosh

Instructor

Kasada ödeme yapan kişi, alışveriş sepeti ve mağaza

Ekranda SQL kodu olan dizüstü bilgisayar ve kahve fincanı

SQL Server'a Giriş

SQL Server ve Transact-SQL

  • SQL Server: Microsoft tarafından geliştirilen ilişkisel veritabanı sistemi

  • Transact-SQL (T-SQL): SQL'in Microsoft sürümü, ek işlevlerle

  • Bu derste: T-SQL'in temellerine hâkim olun

  • Sorgu yazmayı öğrenin

SQL Server'a Giriş

Bir sunucu odasında sunucu rafları

SQL Server'a Giriş

Sorgulama 101

  • SQL Server: veritabanları ve tabloları içeren bir mağaza gibidir

  • Sorgular: farklı reyonlardan öğeleri seçip sepete eklememizi sağlar

  • SELECT: veri getirme ana terimi

SQL Server'a Giriş
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'a Giriş

Birden fazla sütun seçme

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'a Giriş

Sorgu biçimlendirme

SELECT description, event_year, event_date
FROM grid;
SELECT 
  description, 
  event_year, 
  event_date
FROM 
  grid;
SQL Server'a Giriş

TOP () ile seçme

-- 5 satır döndür
SELECT TOP(5) artist
FROM artists;
-- Satırların ilk %5'ini döndür
SELECT TOP(5) PERCENT artist 
FROM artists;
+-----------------------+
| artist                |
|-----------------------|
| AC/DC                 |
| Accept                |
| Aerosmith             |
| Alanis Morissette     |
| Alice in Chains       |
+-----------------------+
SQL Server'a Giriş

DISTINCT ile seçme

-- Tablodaki tüm satırları döndür
SELECT nerc_region 
FROM grid;
+-------------+
| nerc_region |
|-------------|
| RFC         |
| RFC         |
| MRO         |
| MRO         |
| ....        |
+-------------+
-- Benzersiz satırları döndür
SELECT DISTINCT nerc_region 
FROM grid;
+-------------+
| nerc_region |
|-------------|
| NPCC        |
| NPCC RFC    |
| RFC         |
| ERCOT       |
| ...         | 
+-------------+
SQL Server'a Giriş

Select *

-- Tüm satırları döndür
SELECT * 
FROM grid;
  • Büyük tablolar için uygun DEĞİLDİR
SQL Server'a Giriş

AS ile sütun adlarını takma adlandırma

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'a Giriş

Biraz T-SQL yazalım!

SQL Server'a Giriş

Preparing Video For Download...