Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Cours SQL Master Image Numérique ISAMM

1,814 views

Published on

cours sous forme d'exemple, mémo, sur les fonctionnalités fondamentales du SQL en prenant MySQL comme exemple.

Published in: Technology
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Cours SQL Master Image Numérique ISAMM

  1. 1. MEMO MY SQL Un BON exemplevaut mieux quun long cours dis AbdelMonem NAAMANE isamm@naamane.com
  2. 2. Manipulation des bases de donnéesshell> mysql -h host -u user -pmysql> show databasesmysql> USE mabasemysql> QUITCREATE DATABASE nom_base;DROP DATABASE nom_base; AbdelMonem NAAMANE isamm@naamane.com
  3. 3. Créationde table AbdelMonem NAAMANE isamm@naamane.com
  4. 4. Types de données les plus utilisésINTEGER (INT) : Entier positif ou négatif. 4 octet (-2³² → 2³²-1 )FLOAT : Un nombre à virgule flottante. 4 octet(-/+1.17E-38 → -/+3.40E+38)TIME : Heure, de 00:00:00 à 23:59:59DATE : Une date, de 1000-01-01 à 9999-12-31 au maximum.DATETIME : Date et Heure, de 1000-01-01 00:00:00 à 9999-12-31 23:59:59VARCHAR : Chaîne de caractère, (1 → 255 caractères)TEXT : Chaîne de caractère, max 2¹⁶-1 octetENUM (valeur1,valeur2,...) Liste de 65 535 valeurs au maximum.SET (valeur1,valeur2,...) Liste de 65 535 valeurs au maximum. AbdelMonem NAAMANE isamm@naamane.com
  5. 5. Création de tableCREATE TABLE Etudiant (id_etudiant INT(6),nom VARCHAR(255) NOT NULL,note FLOAT(7,2) DEFAULT 0,classe INT,cin INT(6),CONSTRAINT PK_etudiant PRIMARY KEY(identifiant),CONSTRAINT UNIQUE (cin),CONSTRAINT FK_etu_classe FOREIGN KEY (classe)REFERENCES Classe(id_classe) ON DELETE CASCADE);RENAME TABLE Etudiant TO eleves; AbdelMonem NAAMANE isamm@naamane.com
  6. 6. Manipulation de la structure AbdelMonem NAAMANE isamm@naamane.com
  7. 7. Manipulation de la structure 1/2DROP TABLE nom_table;ALTER TABLE client DROP tel;ALTER TABLE Etudiant DROP PRIMARY KEY;ALTER TABLE Etudiant RENAME COL1 TO COL3;ALTER TABLE Etudiant MODIFY nom_elevevarchar(40) NOT NULL AbdelMonem NAAMANE isamm@naamane.com
  8. 8. Manipulation de la structure 2/2ALTER TABLE Etudiant ADD UNIQUE cin;ALTER TABLE etudiantADD (Ville VARCHAR(255) DEFAULT Tunis,Pays VARCHAR(30) );ALTER TABLE Etudiant ADD CONSTRAINTFOREIGN KEY (classe) REFERENCESClasse(id_classe)); AbdelMonem NAAMANE isamm@naamane.com
  9. 9. Insertion dedonnées AbdelMonem NAAMANE isamm@naamane.com
  10. 10. Insertion de données 1/2INSERT INTO nom_de_tableVALUES(4,15,NAAMANE, 2011-11-11) ;INSERT INTO nom_de_table (col1,col2,col3)VALUES (1,2,3),(4,5,6);INSERT INTO nom_de_tableSET col3 = 1, col5 = 2011-11-11;INSERT INTO table1 (clonne1, colonne2) SELECT nom, age FROM table2 WHERE age > 18; AbdelMonem NAAMANE isamm@naamane.com
  11. 11. Insertion de données 2/2REPLACE INTO nom_de_table (col1,col2,col3)VALUES (1,2,3),(4,5,6);LOAD DATA LOCAL IN FILE "fichier.txt"INTO etudiantsFIELDS TERMINATED BY ","LINES TERMINATED BY "rn"IGNORE 1 LINES AbdelMonem NAAMANE isamm@naamane.com
  12. 12. Mise àjour desdonnées AbdelMonem NAAMANE isamm@naamane.com
  13. 13. Mise à jour des donnéesUPDATE clientsSET prenom =Mohamed, nom =NAAMANE,ville = Bizerte, enfants = 2WHERE id > 10ORDER BY note DESCLIMIT 20;UPDATE clientsSET note = note+4;UPDATE clientsSET classe = REPLACE( classe,MIN,Master IM) AbdelMonem NAAMANE isamm@naamane.com
  14. 14. Suppressiondes données AbdelMonem NAAMANE isamm@naamane.com
  15. 15. Suppression des donnéesDELETE FROM clientsWHERE age = 20AND ville LIKE %uni%ORDER BY note DESClimit 10;TRUNCATE clients; AbdelMonem NAAMANE isamm@naamane.com
  16. 16. Selection dedonnées AbdelMonem NAAMANE isamm@naamane.com
  17. 17. Selection de données simpleSELECT *FROM etudiant ;SELECT nom, prenom, note, date_naissanceFROM etudiantORDER BY note DESC; [ASC | DESC]SELECT nom, prenom, cin, noteFROM etudiantWHERE ville = TunisAND note > 10OR ville = BizerteAND nom != AAND prenom LIKE Mo%; AbdelMonem NAAMANE isamm@naamane.com
  18. 18. Selection : fonctions utililes 1SELECT 1+2, "bon, Jour";SELECT CONCAT(prenom, " ", nom) AS nom_completFROM etudiants;SELECT *FROM etudiantsWHERE age IS NULL;SELECT *FROM etudiantsWHERE age IS NOT NULL; AbdelMonem NAAMANE isamm@naamane.com
  19. 19. Selection : fonctions utililes 2SELECT *FROM etudiantsWHERE date_naissance > 1980-12-15AND date_naissance < 2005-05-10;SELECT *FROM etudiantsWHERE MONTH(date_naissance) = 2AND DAYOFMONTH(date_naissance) = 29;SELECT *FROM etudiantsWHERE nom LIKE A%AND prenom LIKE __b%N; AbdelMonem NAAMANE isamm@naamane.com
  20. 20. Selection : fonctions utililes 3SELECT DISTINCT villeFROM etudiants;SELECT COUNT(*), COUNT(ville)FROM etudiants;SELECT COUNT(DISTINCT ville)FROM etudiants; AbdelMonem NAAMANE isamm@naamane.com
  21. 21. Selection : fonctions utililes 4SELECT *FROM etudiantsWHERE age IN (11,12,13,14,15);SELECT DISTINCT nom_livreFROM livreWHERE type_livre NOT IN (SELECT type_livre FROM anciens_livre);SELECT *FROM etudiantsORDER BY RAND()LIMIT 1; AbdelMonem NAAMANE isamm@naamane.com
  22. 22. Fonctions pour dateNOW() → 2012-11-10 33:44:21CURDATE() → 2012-11-10CURTIME() → 20:11:09DATE_ADD(2000-11-16, 3 YEAR) → MONTH | DAY | HOUR | MINUTE |SECONDDATE_SUB(2000-11-16, 3 YEAR) → MONTH | DAY | HOUR | MINUTE |SECONDYEAR()MONTH()DAY()HOUR()MINUTE()SECOND() AbdelMonem NAAMANE isamm@naamane.com
  23. 23. GroupementSELECT MAX(note), MIN(note), SUM(note),AVG(note),COUNT(note), COUNT(*),FROM etudiant;SELECT article, sum(montant) as MFROM venteGROUP BY article;SELECT article, sum(montant)FROM venteWHERE date_achat > 2011-01-01GROUP BY article;SELECT article, sum(montant)FROM venteGROUP BY articleHAVING sum(montant) > 100); AbdelMonem NAAMANE isamm@naamane.com
  24. 24. Groupement 2SELECT nom_article, sum(montant), max(montant),max(date_vente) AS date_derniere_venteFROM venteWHERE date_achat > 2011-01-01AND nom_article != AAND prenom LIKE ch%GROUP BY articleHAVING sum(montant) > 100ORDER BY date_derniere_vente DESClimit 5; AbdelMonem NAAMANE isamm@naamane.com
  25. 25. JointureSELECT *FROM etudiant , classeWHERE etudiant.classe = classe.id_classeAND classe.niveau_classe >= 2SELECT *FROM classeLEFT JOIN etudiantON etudiant.classe = classe.id_classeWHERE classe.niveau_classe >= 2; AbdelMonem NAAMANE isamm@naamane.com
  26. 26. MEMO MY SQLAbdelMonem NAAMANE isamm@naamane.com

×