( Ļ) DDL (Data Definition Language), SQL, . , , SQL DML (Data Manipulation Language), . , .
1. INSERT. , , .
"news" 4 ("id", "posted", "content", "author") :
INSERT INTO `news` VALUES (1, NOW(), " ", "");
"NOW()" MySQL , , , "posted" .
"news" 4 ("id", "posted", "content", "author") :
INSERT INTO `news` (`posted`, `content`) VALUES (NOW(), " ");
"posted" "content". "id" , "id" ( 1, ), "author" NULL ( ).
2. UPDATE. , , , .
, , "author" "news" "", "content" " ", :
UPDATE `news` SET `author` = "", `content` = " ";
, . (WHERE), .
, "content" " " "id", 1, "news", :
UPDATE `news` SET `content` = " " WHERE id = 1;
|
|
.
3. DELETE. . , , WHERE ( , UPDATE) , , . .
, "news" "id", 1, :
DELETE FROM `news` WHERE id = 1;
SELECT. :
SELECT `my_field1`, `my_field2`,..., `my_fieldN`
FROM `my_table`
WHERE ;
:
my_field1, my_field2 .. , "", .. . , , (*).
my_table , .
WHERE .
, "news" :
SELECT * FROM `news`;
, , , .
(WHERE) . AND, OR, NOT SQL. (( )).
1. : (=); (>=), (<=), (<> !=). , "content" "news", "id" 42, :
SELECT `content` FROM `news` WHERE `id` < 42;
2. () AND , . "content" "news", "id" 21 42:
SELECT `content` FROM `news` WHERE `id` > 21 AND `id` < 42;
3. () OR , , . "content" "news", "id" 21 10:
SELECT `content` FROM `news` WHERE `id` > 21 OR `id` < 10;
, . "content" "news", "id" 21 42, 84:
|
|
SELECT `content` FROM `news` WHERE (`id` > 21 AND `id` < 42) OR `id` > 84;
4. () NOT . , "content" "news", "id" 21 42, :
SELECT `content` FROM `news` WHERE NOT (`id` >= 21 AND `id` <= 42);
5. , NULL (NULL , : , NULL ). IS NULL. "content" "news", "author" :
SELECT `content` FROM `news` WHERE `author` IS NULL;
6. - BEETWEEN.. AND. "BETWEEN a AND b". "content" "news", "id" 21 42:
SELECT `content` FROM `news` WHERE `id` BETWEEN 21 AND 42;
7. - IN. "content" "news", "id" 21, 42, 84 168:
SELECT `content` FROM `news` WHERE `id` IN (21, 42, 84, 168);
8. , , LIKE. LIKE , _ ( ) % ( ). "content" "news", "author" _user% (.. , + user + ):
SELECT `content` FROM `news` WHERE `author` LIKE "_user%";
1user, 1user222, xuser42 ..