Declare yourself

Introductie tot SQL Server

John MacKintosh

Instructor

Variabelen

SELECT * 
FROM artist 
WHERE name = 'AC/DC';

Pas de query nu aan voor een andere artiest:

SELECT * 
FROM artist 
WHERE name = 'U2';

Maak om herhaling te voorkomen een variabele:

SELECT * 
FROM artist 
WHERE name = @my_artist;
Introductie tot SQL Server

DECLARE

DECLARE @

Integer-variabele:

DECLARE @test_int INT

Varchar-variabele:

DECLARE @my_artist VARCHAR(100)
Introductie tot SQL Server

SET

Integer-variabele:

DECLARE @test_int INT

SET @test_int = 5

Waarde toekennen aan @my_artist:

DECLARE @my_artist  varchar(100)

SET @my_artist = 'AC/DC'
Introductie tot SQL Server
DECLARE @my_artist varchar(100)
DECLARE @my_album varchar(300);

SET @my_artist = 'AC/DC'
SET @my_album  = 'Let There Be Rock' ;

SELECT --
FROM --
WHERE artist = @my_artist
AND album = @my_album;
DECLARE @my_artist varchar(100)
DECLARE @my_album varchar(300);

SET @my_artist = 'U2'
SET @my_album  = 'Pop' ;

SELECT --
FROM --
WHERE artist = @my_artist
AND album = @my_album;
Introductie tot SQL Server

Tijdelijke tabellen

SELECT 
  col1, 
  col2, 
  col3 INTO #my_temp_table
FROM my_existing_table 
WHERE 
  -- Conditions
  • #my_temp_table blijft bestaan tot de connectie of sessie eindigt
-- Tabel handmatig verwijderen
DROP TABLE #my_temp_table
Introductie tot SQL Server

Laten we wat variabelen declareren!

Introductie tot SQL Server

Preparing Video For Download...