Apache Derby - Syntaxe

Ce chapitre vous donne la syntaxe de toutes les instructions SQL Apache Derby.

Toutes les instructions commencent par l'un des mots-clés tels que SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE, SHOW et toutes les instructions se terminent par un point-virgule (;).

Les instructions SQL d'Apache Derby sont sensibles à la casse, y compris les noms de table.

Instruction CREATE

CREATE TABLE table_name (
   column_name1 column_data_type1 constraint (optional),
   column_name2 column_data_type2 constraint (optional),
   column_name3 column_data_type3 constraint (optional)
);

DROP TABLE

DROP TABLE table_name;

Instruction INSERT

INSERT INTO table_name VALUES (column_name1, column_name2, ...);

Instruction SELECT

SELECT column_name, column_name, ... FROM table_name;

Déclaration UPDATE

UPDATE table_name
   SET column_name = value, column_name = value, ...
   WHERE conditions;

Instruction DELETE

DELETE FROM table_name WHERE condition;

Instruction DESCRIBE

Describe table_name

Instruction SQL TRUNCATE TABLE

TRUNCATE TABLE table_name;

Instruction ALTER - Ajout d'une colonne

ALTER TABLE table_name ADD COLUMN column_name column_type;

Instruction ALTER - Ajout d'une contrainte

ALTER TABLE table_name ADD CONSTRAINT constraint_name constraint (column_name);

Instruction ALTER - Colonne en baisse

ALTER TABLE table_name DROP COLUMN column_name;

Instruction ALTER - Suppression de la contrainte

ALTER TABLE table_name DROP CONSTRAINT constraint_name;

Clause WHERE

SELECT * from table_name WHERE condition;
or,
DELETE from table_name WHERE condition;
or,
UPDATE table_name SET column_name = value WHERE condition;

Clause GROUP BY

SELECT column1, column2, . . . table_name GROUP BY column1, column2, . . .;

ORDER BY Clause

SELECT * FROM table_name ORDER BY column_name ASC|DESC.

Avoir une clause

SELECT column1, column2 . . . from table_name GROUP BY column having
condition;

Créer un index

CTREATE INDEX index_name on table_name (column_name);

Créer un index UNIQUE

CREATE UNIQUE INDEX index_name on table_name (column_name);

Créer un index COMPOSITE

CREATE INDEX index_name on table_name (column_name1, column_name2);

Affichage des index

SHOW INDEXES FROM table_name;

Suppression d'index

DROP INDEX index_name;