Introduction to SQL
tags: #sql
What is SQL?
SQL is a Data Manipulation Language used to manipulate database (access, modify or retrieve the data).
This is different from Data Definition Language for specifying database schema structure.
SQL was originally coined as "SEQUEL"
- S - Structure
- E - English
- QUE - Query
- L - Language
Now popularly known as SQL - Structured Query Language
Executing SQL Statements
In SQL, a semicolon (;) is used to mark the end of a SQL statement.
It is used as a separator between multiple SQL statements in a batch, and it tells the database engine where each statement ends and where the next one begins.
This also makes your SQL code more portable and more consistent across different database platforms (not all DBMS require ; at the end of each statement).
Meaning of NULL
Meaning of NULL differs by context and data you are working with, but can be a result of:
- Unknown value due the value being absent
- Unavailable or withheld value
- Not applicable attribute
- Cannot do comparison with
NULLvalues (incl.NULL=NULL)
Logical Values in SQL
SQL uses a three-valued logic involving: TRUE, FALSE, and UNKNOWN
UNKNOWN and how is it different from NULL?
UNKNOWN is a special value in SQL that represents missing, unknown, or inapplicable data. It is typically used in situations where the actual value of a data item is not known or cannot be determined.
NULL is a value that represents the absence of a value, whereas UNKNOWN represents a missing or unknown value that cannot be determined.
Logical Connectives
| AND CONNECTIVE | TRUE | FALSE | UNKNOWN |
|---|---|---|---|
| TRUE | TRUE | FALSE | UNKNOWN |
| FALSE | FALSE | FALSE | FALSE |
| UNKNOWN | UKNOWN | FALSE | UNKNOWN |
| OR CONNECTIVE | TRUE | FALSE | UNKNOWN |
|---|---|---|---|
| TRUE | TRUE | TRUE | TRUE |
| FALSE | TRUE | FALSE | UNKNOWN |
| UNKNOWN | TRUE | UNKNOWN | UNKNOWN |
| NOT CONNECTIVE | |
|---|---|
| TRUE | FALSE |
| FALSE | TRUE |
| UNKNOWN | UNKNOWN |