Annotated edit history of
SQL version 9, including all changes.
View license author blame.
Rev |
Author |
# |
Line |
7 |
AristotlePagaltzis |
1 |
[Acronym] for __S__tructured __Q__uery __L__anguage. Some DataBase professionals think the ''S'' should stand for "stupid." |
1 |
PerryLorier |
2 |
|
7 |
AristotlePagaltzis |
3 |
[SQL] is a set-centric ProgrammingLanguage in which statements are excuted over a [Schema] of relations (tables), and return a table of results. |
2 |
StuartYeates |
4 |
|
7 |
AristotlePagaltzis |
5 |
!! Syntax and examples |
3 |
AristotlePagaltzis |
6 |
|
7 |
AristotlePagaltzis |
7 |
In this example, imagine we have a table called <tt>users</tt> which has an <tt>id</tt>, a <tt>name</tt> and an <tt>accesslevel</tt> column. |
6 |
CraigBox |
8 |
|
|
|
9 |
__Retrieving data:__ |
|
|
10 |
|
7 |
AristotlePagaltzis |
11 |
<pre> |
9 |
AristotlePagaltzis |
12 |
SELECT ''col_1'', ''col_2'', ''col_n'' FROM ''table'' WHERE ''condition'' |
7 |
AristotlePagaltzis |
13 |
</pre> |
|
|
14 |
|
|
|
15 |
Eg. to find the access level of user number 154:'''' |
|
|
16 |
|
|
|
17 |
<pre> |
|
|
18 |
SELECT accesslevel FROM users WHERE id = 154; |
|
|
19 |
</pre> |
6 |
CraigBox |
20 |
|
|
|
21 |
__Inserting data:__ |
|
|
22 |
|
7 |
AristotlePagaltzis |
23 |
<pre> |
8 |
DavidHallett |
24 |
INSERT INTO ''table'' (''column_one'', ''column_...'', ''column_n'') VALUES (''value_one'', ''value_...'', ''value_n'') |
7 |
AristotlePagaltzis |
25 |
</pre> |
|
|
26 |
|
|
|
27 |
Eg. to add a new user:'''' |
|
|
28 |
|
|
|
29 |
<pre> |
|
|
30 |
INSERT INTO users (name, accesslevel) VALUES ('Craig', 10); |
|
|
31 |
</pre> |
|
|
32 |
|
|
|
33 |
The next available ID number is automatically assigned. |
6 |
CraigBox |
34 |
|
|
|
35 |
__Updating data:__ |
|
|
36 |
|
7 |
AristotlePagaltzis |
37 |
<pre> |
8 |
DavidHallett |
38 |
UPDATE ''table'' SET ''column_one''=''value_one'', ''column_...''=''value_...'', ''column_n''=''value_n'' WHERE ''condition'' |
7 |
AristotlePagaltzis |
39 |
</pre> |
|
|
40 |
|
|
|
41 |
Eg. to set an accesslevel of 15 to everyone whos name starts with a C:'''' |
|
|
42 |
|
|
|
43 |
<pre> |
|
|
44 |
UPDATE users SET accesslevel=15 WHERE name LIKE 'C%'; |
|
|
45 |
</pre> |
6 |
CraigBox |
46 |
|
|
|
47 |
__Removing data:__ |
|
|
48 |
|
7 |
AristotlePagaltzis |
49 |
<pre> |
|
|
50 |
DELETE FROM ''table'' WHERE ''condition'' |
|
|
51 |
</pre> |
|
|
52 |
|
|
|
53 |
Eg. to remove the user with ID number 30:'''' |
|
|
54 |
|
|
|
55 |
<pre> |
|
|
56 |
DELETE FROM users WHERE id = 30; |
|
|
57 |
</pre> |
4 |
AristotlePagaltzis |
58 |
|
|
|
59 |
---- |
7 |
AristotlePagaltzis |
60 |
Part of CategoryProgrammingLanguages and CategorySpecialPurposeProgrammingLanguages |