Sql
De Linuxmemo.
(Différences entre les versions)
(→Transaction SQL) |
(→Références) |
||
| Ligne 69 : | Ligne 69 : | ||
UPDATE table2 SET summary=@A WHERE type=1; | UPDATE table2 SET summary=@A WHERE type=1; | ||
COMMIT; | COMMIT; | ||
| + | |||
| + | ==Using AUTO_INCREMENT== | ||
| + | CREATE TABLE animals ( | ||
| + | id MEDIUMINT NOT NULL AUTO_INCREMENT, | ||
| + | name CHAR(30) NOT NULL, | ||
| + | PRIMARY KEY (id) | ||
| + | ); | ||
| + | INSERT INTO animals (name) VALUES | ||
| + | ('dog'),('cat'),('penguin'), | ||
| + | ('lax'),('whale'),('ostrich'); | ||
| + | SELECT * FROM animals; | ||
==Références== | ==Références== | ||
Version actuelle en date du 14 février 2019 à 15:23
Structured Query Language
Sommaire |
[modifier] Astuces
- ajouter un utilisateur:
GRANT ALL PRIVILEGES ON base.* TO 'user'@'localhost' IDENTIFIED BY 'un_mot_de_passe' WITH GRANT OPTION;
- recharger les droits:
FLUSH PRIVILEGES;
Facultatif:
GRANT RELOAD,PROCESS ON *.* TO 'user'@'localhost'; GRANT USAGE ON *.* TO 'user'@'localhost';
- voir les droits pour un utilisateur
SHOW GRANTS FOR 'user'@'localhost';
- Commentaire
-- pour une ligne
/* caractère de début pour plusieurs ligne */ caractère de fin
[modifier] Jointures
Exemple: Metasploit#DB_Postgres_jointures
[modifier] Opérateur de comparaison dabs la clause WHERE
= (Égal à) > (Supérieur à) < (Inférieur à) >= (Supérieur ou égal à) <= (Inférieur ou égal à) <> (Différent de) != (Différent de) !< (Non inférieur à) !> (Non supérieur à) BETWEEN Between an inclusive range LIKE Search for a pattern IN To specify multiple possible values for a column
avec like '%' = Chaîne de caractères '_' = Un seul caractère select NAME,VERSION,PUBLISHER from ocsweb.softwares where NAME LIKE "%firefox%"; SELECT COUNT(*) FROM foo WHERE bar NOT LIKE '%baz%' OR bar IS NULL;
[modifier] Transaction SQL
START TRANSACTION, COMMIT, and ROLLBACK Syntax
START TRANSACTION
[transaction_characteristic [, transaction_characteristic] ...]
transaction_characteristic: {
WITH CONSISTENT SNAPSHOT
| READ WRITE
| READ ONLY
}
BEGIN [WORK]
COMMIT [WORK] [AND [NO] CHAIN] [[NO] RELEASE]
ROLLBACK [WORK] [AND [NO] CHAIN] [[NO] RELEASE]
SET autocommit = {0 | 1}
Exemple:
START TRANSACTION; SELECT @A:=SUM(salary) FROM table1 WHERE type=1; UPDATE table2 SET summary=@A WHERE type=1; COMMIT;
[modifier] Using AUTO_INCREMENT
CREATE TABLE animals (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO animals (name) VALUES
('dog'),('cat'),('penguin'),
('lax'),('whale'),('ostrich');
SELECT * FROM animals;
[modifier] Références
- Référence absolues: base.table.colonne
- Référence relative (apres selection de la base): table.colonne