SQL handleiding

SQL TUIS SQL Inleiding SQL-sintaksis SQL Kies SQL Kies Distinct SQL Waar SQL En, of, nie SQL Bestel deur SQL Voeg in SQL nulwaardes SQL-opdatering SQL verwyder SQL Kies Top SQL Min en Max SQL-telling, gemiddeld, som SQL Soos SQL Wildcards SQL in SQL Tussen SQL aliasse SQL sluit aan SQL Inner Sluit aan SQL Links Sluit aan SQL Reg Sluit aan SQL Volledige Aansluiting SQL Self Sluit aan SQL Unie SQL Groep deur SQL het SQL bestaan SQL Enige, Almal SQL Kies In SQL Voeg in Kies SQL-geval SQL nul-funksies SQL gestoorde prosedures SQL opmerkings SQL-operateurs

SQL- databasis

SQL Skep DB SQL Drop DB SQL Backup DB SQL Skep tabel SQL Drop Tabel SQL Verander Tabel SQL-beperkings SQL nie nul nie SQL Uniek SQL Primêre Sleutel SQL buitelandse sleutel SQL Check SQL verstek SQL-indeks SQL Outo-verhoging SQL datums SQL-aansigte SQL-inspuiting SQL Hosting SQL-datatipes

SQL- verwysings

SQL sleutelwoorde MySQL-funksies SQL Server funksies MS Access funksies SQL Vinnige Verw

SQL voorbeelde

SQL voorbeelde SQL vasvra SQL-oefeninge SQL-sertifikaat

SQL NULL-waardes


Wat is 'n NULL-waarde?

'n Veld met 'n NULL-waarde is 'n veld met geen waarde nie.

As 'n veld in 'n tabel opsioneel is, is dit moontlik om 'n nuwe rekord in te voeg of 'n rekord by te werk sonder om 'n waarde by hierdie veld te voeg. Dan sal die veld gestoor word met 'n NULL waarde.

Let wel: 'n NULL-waarde verskil van 'n nulwaarde of 'n veld wat spasies bevat. 'n Veld met 'n NULL-waarde is een wat leeg gelaat is tydens rekordskepping!


Hoe om te toets vir NULL-waardes?

Dit is nie moontlik om vir NULL-waardes te toets met vergelykingsoperateurs, soos =, < of <>.

Ons sal eerder die IS NULLen IS NOT NULLoperateurs moet gebruik.

IS NULL Sintaksis

SELECT column_names
FROM table_name
WHERE column_name IS NULL;

IS NIE NULL sintaksis nie

SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;

Demo-databasis

Hieronder is 'n keuse uit die "Klante"-tabel in die Noordewind-voorbeelddatabasis:

CustomerID CustomerName ContactName Address City PostalCode Country
1

Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Germany
2 Ana Trujillo Emparedados y helados Ana Trujillo Avda. de la Constitución 2222 México D.F. 05021 Mexico
3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico
4

Around the Horn Thomas Hardy 120 Hanover Sq. London WA1 1DP UK
5 Berglunds snabbköp Christina Berglund Berguvsvägen 8 Luleå S-958 22 Sweden


Die IS NULL-operateur

Die IS NULLoperateur word gebruik om te toets vir leë waardes (NULL-waardes).

Die volgende SQL lys alle kliënte met 'n NULL waarde in die "Adres" veld:

Voorbeeld

SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NULL;

Wenk: Gebruik altyd IS NULL om NULL-waardes te soek.


Die IS NIE NULL-operateur nie

Die IS NOT NULLoperateur word gebruik om te toets vir nie-leë waardes (NIE NULL waardes nie).

Die volgende SQL lys alle kliënte met 'n waarde in die "Adres" veld:

Voorbeeld

SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NOT NULL;

Toets jouself met oefeninge

Oefening:

Kies alle rekords van Customerswaar die PostalCodekolom leeg is.

SELECT * FROM Customers
WHERE   ;