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.

Les Contraintes | SQL Oracle

2,851 views

Published on

Les Contraintes | SQL Oracle. Telecharger cours sql oracle gratuit.Gérer les Contraintes, Créer des contraintes

Published in: Education
  • 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 THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... 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 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 THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... 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 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
  • Be the first to like this

Les Contraintes | SQL Oracle

  1. 1. Copyright © Oracle Corporation, 1998. Tous droits réservés. 1414 Les Contraintes www.TelechargerCours.com
  2. 2. 14-2 Copyright © Oracle Corporation, 1998. Tous droits réservés. Objectifs A la fin de ce chapitre, vous saurez :A la fin de ce chapitre, vous saurez : • Définir les contraintes • Créer des contraintes et les maintenir www.TelechargerCours.com
  3. 3. 14-3 Copyright © Oracle Corporation, 1998. Tous droits réservés. Les Contraintes • Les contraintes contrôlent des règles de gestion au niveau d'une table. • Les contraintes empêchent la suppression d'une table lorsqu'il existe des dépendances. • Types de contraintes valides dans Oracle : – NOT NULL – UNIQUE – PRIMARY KEY – FOREIGN KEY – CHECK
  4. 4. 14-4 Copyright © Oracle Corporation, 1998. Tous droits réservés. Conventions Applicables aux Contraintes • Si vous ne nommez pas une contrainte, Oracle8 Server créera un nom au format SYS_Cn. • Vous pouvez créer une contrainte : – En même temps que la création de la table – Une fois que la table est créée • Définissez une contrainte peut être définie au niveau table ou colonne. • Consulter le dictionnaire de données pour retrouver une contrainte.
  5. 5. 14-5 Copyright © Oracle Corporation, 1998. Tous droits réservés. Les Contraintes CREATE TABLE [schema.]table (column datatype [DEFAULT expr] [column_constraint], … [table_constraint]); CREATE TABLE emp( empno NUMBER(4), ename VARCHAR2(10), … deptno NUMBER(2) NOT NULL, CONSTRAINT emp_empno_pk PRIMARY KEY (EMPNO)); www.TelechargerCours.com
  6. 6. 14-6 Copyright © Oracle Corporation, 1998. Tous droits réservés. Les Contraintes • Contrainte au niveau colonne • Contrainte au niveau table column [CONSTRAINT constraint_name] constraint_type,column [CONSTRAINT constraint_name] constraint_type, column,... [CONSTRAINT constraint_name] constraint_type (column, ...), column,... [CONSTRAINT constraint_name] constraint_type (column, ...), www.TelechargerCours.com
  7. 7. 14-7 Copyright © Oracle Corporation, 1998. Tous droits réservés. La Contrainte NOT NULL Interdit la présence de valeurs NULL dansInterdit la présence de valeurs NULL dans la colonnela colonne EMPEMP EMPNO ENAME JOB ... COMM DEPTNO 7839 KING PRESIDENT 10 7698 BLAKE MANAGER 30 7782 CLARK MANAGER 10 7566 JONES MANAGER 20 ... Contrainte NOT NULLContrainte NOT NULL (aucune ligne ne peut(aucune ligne ne peut avoir de valeur NULLavoir de valeur NULL dans cette colonne)dans cette colonne) Absence de contrainteAbsence de contrainte NOT NULLNOT NULL (toute ligne peut avoir(toute ligne peut avoir une valeur NULL dansune valeur NULL dans cette colonne)cette colonne) ContrainteContrainte NOT NULLNOT NULL www.TelechargerCours.com
  8. 8. 14-8 Copyright © Oracle Corporation, 1998. Tous droits réservés. La Contrainte NOT NULL Se définit au niveau colonneSe définit au niveau colonne SQL> CREATE TABLE emp( 2 empno NUMBER(4), 3 ename VARCHAR2(10) NOT NULL, 4 job VARCHAR2(9), 5 mgr NUMBER(4), 6 hiredate DATE, 7 sal NUMBER(7,2), 8 comm NUMBER(7,2), 9 deptno NUMBER(2) NOT NULL); www.TelechargerCours.com
  9. 9. 14-9 Copyright © Oracle Corporation, 1998. Tous droits réservés. La Contrainte de Clé UNIQUE DEPTDEPT DEPTNO DNAME LOC ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON contrainte de clé UNIQUEcontrainte de clé UNIQUE 50 SALES DETROIT 60 BOSTON A insérerA insérer InterditInterdit (DNAME(DNAMESALES existe déjà)existe déjà) AutoriséAutorisé www.TelechargerCours.com
  10. 10. 14-10 Copyright © Oracle Corporation, 1998. Tous droits réservés. La Contrainte de Clé UNIQUE Se définit au niveau table ou colonneSe définit au niveau table ou colonne SQL> CREATE TABLE dept( 2 deptno NUMBER(2), 3 dname VARCHAR2(14), 4 loc VARCHAR2(13), 5 CONSTRAINT dept_dname_uk UNIQUE(dname)); www.TelechargerCours.com
  11. 11. 14-11 Copyright © Oracle Corporation, 1998. Tous droits réservés. La Contrainte PRIMARY KEY DEPTDEPT DEPTNO DNAME LOC ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON clé PRIMAIREclé PRIMAIRE A insérerA insérer 20 MARKETING DALLAS FINANCE NEW YORK interdit (DEPTNOinterdit (DEPTNO−2020 existe déjà)existe déjà) interditinterdit (DEPTNO est NULL)(DEPTNO est NULL) www.TelechargerCours.com
  12. 12. 14-12 Copyright © Oracle Corporation, 1998. Tous droits réservés. La Contrainte PRIMARY KEY Se définit au niveau table ou colonneSe définit au niveau table ou colonne SQL> CREATE TABLE dept( 2 deptno NUMBER(2), 3 dname VARCHAR2(14), 4 loc VARCHAR2(13), 5 CONSTRAINT dept_dname_uk UNIQUE (dname), 6 CONSTRAINT dept_deptno_pk PRIMARY KEY(deptno)); www.TelechargerCours.com
  13. 13. 14-13 Copyright © Oracle Corporation, 1998. Tous droits réservés. La Contrainte FOREIGN KEY DEPTDEPT DEPTNO DNAME LOC ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS ... PRIMARYPRIMARY KEYKEY EMPEMP EMPNO ENAME JOB ... COMM DEPTNO 7839 KING PRESIDENT 10 7698 BLAKE MANAGER 30 ... FOREIGNFOREIGN KEYKEY 7571 FORD MANAGER ... 200 9 7571 FORD MANAGER ... 200 A insérerA insérer InterditInterdit (DEPTNO(DEPTNO9 n'existe pasn'existe pas dans la tabledans la table DEPTDEPT AutoriséAutorisé www.TelechargerCours.com
  14. 14. 14-14 Copyright © Oracle Corporation, 1998. Tous droits réservés. La Contrainte FOREIGN KEY Se définit au niveau table ou colonneSe définit au niveau table ou colonne SQL> CREATE TABLE emp( 2 empno NUMBER(4), 3 ename VARCHAR2(10) NOT NULL, 4 job VARCHAR2(9), 5 mgr NUMBER(4), 6 hiredate DATE, 7 sal NUMBER(7,2), 8 comm NUMBER(7,2), 9 deptno NUMBER(2) NOT NULL, 10 CONSTRAINT emp_deptno_fk FOREIGN KEY (deptno) 11 REFERENCES dept (deptno)); www.TelechargerCours.com
  15. 15. 14-15 Copyright © Oracle Corporation, 1998. Tous droits réservés. Mots-clés Associés à la Contrainte FOREIGN KEY • FOREIGN KEY – Définit la colonne dans la table détail dans une contrainte de niveau table • REFERENCES – Identifie la table et la colonne de la table maître • ON DELETE CASCADE – Autorise la suppression d’une ligne dans la table maître et des lignes dépendantes dans la table détail
  16. 16. 14-16 Copyright © Oracle Corporation, 1998. Tous droits réservés. La Contrainte CHECK • Définit une condition que chaque ligne doit obligatoirement satisfaire • Expressions interdites : – Références aux pseudo-colonnes CURRVAL, NEXTVAL, LEVEL et ROWNUM – Appels aux fonctions SYSDATE, UID, USER et USERENV – Requêtes faisant référence à d'autres valeurs dans d'autres lignes ..., deptno NUMBER(2), CONSTRAINT emp_deptno_ck CHECK (DEPTNO BETWEEN 10 AND 99),... www.TelechargerCours.com
  17. 17. 14-17 Copyright © Oracle Corporation, 1998. Tous droits réservés. Ajout d'une Contrainte • Vous pouvez ajouter ou supprimer une contrainte, mais pas la modifier • Vous pouvez activer ou désactiver des contraintes • Pour ajouter une contrainte NOT NULL, utilisez la clause MODIFY ALTER TABLE table ADD [CONSTRAINT constraint] type (column); ALTER TABLE table ADD [CONSTRAINT constraint] type (column); www.TelechargerCours.com
  18. 18. 14-18 Copyright © Oracle Corporation, 1998. Tous droits réservés. Ajout d'une Contrainte Ajouter une contrainte FOREIGN KEY à laAjouter une contrainte FOREIGN KEY à la table EMP précisant qu'un manager doittable EMP précisant qu'un manager doit déjà exister dans la table EMP en tantdéjà exister dans la table EMP en tant qu'employé valide.qu'employé valide. SQL> ALTER TABLE emp 2 ADD CONSTRAINT emp_mgr_fk 3 FOREIGN KEY(mgr) REFERENCES emp(empno); Table altered.Table altered. www.TelechargerCours.com
  19. 19. 14-19 Copyright © Oracle Corporation, 1998. Tous droits réservés. Suppression d'une Contrainte • Supprimer de la table EMP la contrainte concernant le manager. SQL> ALTER TABLE emp 2 DROP CONSTRAINT emp_mgr_fk; Table altered.Table altered. SQL> ALTER TABLE emp 2 DROP CONSTRAINT emp_mgr_fk; Table altered.Table altered. • Supprimer la contrainte PRIMARY KEY de la table DEPT, ainsi que la contrainte FOREIGN KEY associée définie sur la colonne EMP.DEPTNO. SQL> ALTER TABLE dept 2 DROP PRIMARY KEY CASCADE; Table altered.Table altered. SQL> ALTER TABLE dept 2 DROP PRIMARY KEY CASCADE; Table altered.Table altered. www.TelechargerCours.com
  20. 20. 14-20 Copyright © Oracle Corporation, 1998. Tous droits réservés. Désactivation de Contraintes • Pour désactiver une contrainte d'intégrité, utiliser la clause DISABLE de l'ordre ALTER TABLE. • Pour désactiver les contraintes d'intégrité dépendantes, ajouter l'option CASCADE. SQL> ALTER TABLE emp 2 DISABLE CONSTRAINT emp_empno_pk CASCADE; Table altered.Table altered. SQL> ALTER TABLE emp 2 DISABLE CONSTRAINT emp_empno_pk CASCADE; Table altered.Table altered. www.TelechargerCours.com
  21. 21. 14-21 Copyright © Oracle Corporation, 1998. Tous droits réservés. Activation de Contraintes • Pour activer une contrainte d'intégrité actuellement désactivée dans la définition de la table, utiliser la clause ENABLE. • Si vous activez une contrainte UNIQUE ou PRIMARY KEY, un index correspondant est automatiquement créé. SQL> ALTER TABLE emp 2 ENABLE CONSTRAINT emp_empno_pk; Table altered.Table altered. SQL> ALTER TABLE emp 2 ENABLE CONSTRAINT emp_empno_pk; Table altered.Table altered. www.TelechargerCours.com
  22. 22. 14-22 Copyright © Oracle Corporation, 1998. Tous droits réservés. Vérification des Contraintes Pour afficher les définitions et noms dePour afficher les définitions et noms de toutes les contraintes, interrogez la tabletoutes les contraintes, interrogez la table USER_CONSTRAINTS.USER_CONSTRAINTS. CONSTRAINT_NAME C SEARCH_CONDITION ------------------------ - ------------------------- SYS_C00674 C EMPNO IS NOT NULL SYS_C00675 C DEPTNO IS NOT NULL EMP_EMPNO_PK P ... CONSTRAINT_NAME C SEARCH_CONDITION ------------------------ - ------------------------- SYS_C00674 C EMPNO IS NOT NULL SYS_C00675 C DEPTNO IS NOT NULL EMP_EMPNO_PK P ... SQL> SELECT constraint_name, constraint_type, 2 search_condition 3 FROM user_constraints 4 WHERE table_name = 'EMP';
  23. 23. 14-23 Copyright © Oracle Corporation, 1998. Tous droits réservés. Affichage des Colonnes Associées aux Contraintes CONSTRAINT_NAME COLUMN_NAME ------------------------- ---------------------- EMP_DEPTNO_FK DEPTNO EMP_EMPNO_PK EMPNO EMP_MGR_FK MGR SYS_C00674 EMPNO SYS_C00675 DEPTNO CONSTRAINT_NAME COLUMN_NAME ------------------------- ---------------------- EMP_DEPTNO_FK DEPTNO EMP_EMPNO_PK EMPNO EMP_MGR_FK MGR SYS_C00674 EMPNO SYS_C00675 DEPTNO SQL> SELECT constraint_name, column_name 2 FROM user_cons_columns 3 WHERE table_name = 'EMP'; Affichez les colonnes associées aux nomsAffichez les colonnes associées aux noms de contraintes au moyen de la vuede contraintes au moyen de la vue USER_CONS_COLUMNS viewUSER_CONS_COLUMNS view
  24. 24. 14-24 Copyright © Oracle Corporation, 1998. Tous droits réservés. Résumé • Vous pouvez créer des contraintes de type : – NOT NULL – UNIQUE – PRIMARY KEY – FOREIGN KEY – CHECK • Utilisez la table USER_CONSTRAINTS pour afficher les noms et définitions de toutes les contraintes. www.TelechargerCours.com
  25. 25. 14-25 Copyright © Oracle Corporation, 1998. Tous droits réservés. Présentation des Exercices • Ajout de contraintes à des tables existantes • Ajout de colonnes supplémentaires à une table • Affichage d'informations des vues du dictionnaire de données www.TelechargerCours.com

×