Welkom

Introductie tot SQL Server

John MacKintosh

Instructor

shutterstock_1255111450.jpg

shutterstock_418087330.jpg

Introductie tot SQL Server

SQL Server & Transact-SQL

  • SQL Server - relationeel databasesysteem van Microsoft

  • Transact-SQL (T-SQL) - Microsofts SQL-variant met extra functies

  • In deze cursus: beheers de basis van T-SQL

  • Leer queries schrijven

Introductie tot SQL Server

shutterstock_274642010.jpg

Introductie tot SQL Server

Querying 101

  • SQL-server: de winkel met databases en tabellen

  • Queries: hoe we items uit verschillende gangpaden kiezen en in de kar laden

  • SELECT: sleutelwoord om data op te halen

Introductie tot 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           |
| ...                                 |
+-------------------------------------+
Introductie tot SQL Server

Meer dan één kolom selecteren

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         |
+-----------+----------------------+
Introductie tot SQL Server

Query-opmaak

SELECT description, event_year, event_date
FROM grid;
SELECT 
  description, 
  event_year, 
  event_date
FROM 
  grid;
Introductie tot SQL Server

Select TOP ()

-- Geef 5 rijen terug
SELECT TOP(5) artist
FROM artists;
-- Geef de beste 5% rijen terug
SELECT TOP(5) PERCENT artist 
FROM artists;
+-----------------------+
| artist                |
|-----------------------|
| AC/DC                 |
| Accept                |
| Aerosmith             |
| Alanis Morissette     |
| Alice in Chains       |
+-----------------------+
Introductie tot SQL Server

Select DISTINCT

-- Geef alle rijen in de tabel terug
SELECT nerc_region 
FROM grid;
+-------------+
| nerc_region |
|-------------|
| RFC         |
| RFC         |
| MRO         |
| MRO         |
| ....        |
+-------------+
-- Geef unieke rijen terug
SELECT DISTINCT nerc_region 
FROM grid;
+-------------+
| nerc_region |
|-------------|
| NPCC        |
| NPCC RFC    |
| RFC         |
| ERCOT       |
| ...         | 
+-------------+
Introductie tot SQL Server

Select *

-- Geef alle rijen terug
SELECT * 
FROM grid;
  • NIET geschikt voor grote tabellen
Introductie tot SQL Server

Kolomnamen aliassen met 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  |
+------------------------------+
Introductie tot SQL Server

Laten we wat T-SQL schrijven!

Introductie tot SQL Server

Preparing Video For Download...