BASES DE DONNÉES RELATIONNELLES

Slides:



Advertisements
Présentations similaires
Formation au référentiel 1 STG (Sciences et technologie de la gestion)
Advertisements

Introduction aux Entity Beans
Relations avec les entity beans Michel Buffa UNSA
Mise en Forme des Résultats avec SQL*Plus
1 ARCHITECTURE DACCÈS la méthode générale modèle de données définitions module daccès / modules métiers construction des modèles les modules daccès, les.
L'Ordre SELECT Élémentaire
Rappel sur les bases de données et le vocabulaire
Copyright Oracle Corporation, Tous droits réservés. 9 Écriture de Sous- Interrogations Synchronisées.
Les bases de données Cours assuré par: Mlle Smii imen
Chap 4 Les bases de données et le modèle relationnel
SYSTÈME DE GESTION DE BASES DE DONNÉES
Les fonctions de groupes Gestion des transactions
Bases de données et SGBD relationnels
Les requêtes Les requêtes permettent dinterroger une base de données suivant 3 opérateurs : La projection Affiche le contenu dun champ complet En langage.
Algèbre relationnelle et SQL
BASES DE DONNÉES RELATIONNELLES Introduction
SYSTEME DE GESTION DE BASES DE DONNEES
Staf 2x Cours de bases de données
1 PHP 1.Langage PHP 1.1. Types de base, variables et constantes 1.2. Opérateurs et expressions 1.3. Instructions 1.4. Fonctions 2.Accès aux bases de données:
Cours de Base de Données & Langage SQL
Les concepts et les méthodes des bases de données
Michel Tollenaere SQL et relationnel ENSGI Cours MSI 2A Relationnel et SQL version 1.4 du 25 septembre 2007 (ajout jointures) 1 Modèle relationnel Historique.
Christine Bonnet SOURCES : « Samples » dOracle, « Oracle 8 » R. Chapuis PRO*C – C ++
OPTIMISATION DE BASE DE DONNEES ORACLE
Procédures Stockées Schedule: Timing Topic 60 minutes Lecture
EPID-CPI-ISAIP Philippe Bancquart - mise à jour 24/02/ page 1 Gestion des transactions SQLServer.
Introduction.
PHP & My SQL.
Chapitre 5 : Le langage SQL
SQL Partie 1.
Traduction des opérations sous MySQL
Présentation Session RPSI
JDBC L'API JDBC est utilisée pour utilisée pour intéragir avec une base de données.
Les Composants de l’architecture Oracle
Objectifs A la fin de ce chapitre, vous pourrez : présenter l'utilisation d'opérations de chargement de données par chemin direct décrire l'utilisation.
05/02/98WEB ESNIG Modèle logique de données Oracle Designer/2000 & Oracle Web Server.
Manipulation des Données
1 PHP 5 Notions fondamentales (cours #5) Formation continue – Cégep de Sainte-Foy.
Sous-Interrogations.
Sélection de colonnes (la projection)
Les Contraintes.
Quinio1 Bases de données : modèlisation et SGBD Séance 3 B Quinio.
Afficher des Données Issues de Plusieurs Tables
Copyright  Oracle Corporation, Tous droits réservés. 2 Sélection et Tri des Lignes Retournées par un SELECT.
Création et Gestion de Tables
Initiation à Oracle Server
Cours n°4M1.ist-ie (S. Sidhom) UE 203 Promo. M1 IST-IE 2006/07 Conception d’un système d'information sur Internet Architecture trois-tiers : technologies.
 L’information est conservée sous forme de tables  Contient: ◦ Un nom ◦ Une clé primaire ◦ Une liste de colonnes ◦ Les informations/données (sous forme.
Cours Access TuanLoc NGUYEN. Contact Nguyen TuanLoc Tél: Web:
1 Structure en MC Principes Stockage des données dans la mémoire volatile d’un ordinateur Problèmes Stockage temporaire «Petits» volumes de données Langages.
Le langage SQL. Voir polycopié: Introduction à SQL SQL.
06/04/06 LES BASES DE DONNEES INTRODUCTION CogniTIC – Bruxelles Formation - Cepegra.
Copyright  Oracle Corporation, Tous droits réservés. 11 Extraction Hiérarchique.
Séance /10/2004 SGBD - Approches & Principes.
Générateur d’applications WEB de gestion de données Génération de la base de données.
NIVEAU LOGIQUE Vues. Fenêtre dynamique sur la base Ses données proviennent d'autres tables ou d'autres vues.
Introduction Module 1.
Les vues, indexes, séquences.  Qu’est ce qu’une vue 1. Une vue est une vision partielle ou particulière des données d'une ou plusieurs tables de la base.
CONCEPTS BD - Synthèse journée 1 :
Modélisation et utilisation Aurélien Marion1 Aurélien Marion
De Arnault Chazareix :
1 Initiation aux bases de données et à la programmation événementielle VBA sous ACCESS Cours N° 4 Support de cours rédigé par Bernard COFFIN Université.
1 Les bases de données Séance 5 -- Le Langage de Définition de Données ou la manœuvre de la structure de la base -- Le Langage de Manœuvre de Données.
Langage d’interrogation des Données LID
Langage d’interrogation des Données LID
1 Copyright © 2004, Oracle. Tous droits réservés. Extraire des données à l'aide de l'instruction SQL SELECT.
D Copyright © 2004, Oracle. Tous droits réservés. Utiliser SQL*Plus.
Opérateurs Ensemblistes
Transcription de la présentation:

BASES DE DONNÉES RELATIONNELLES CARACTÉRISTIQUES Stockage et gestion de gros volumes de données Bases de données Gros volumes de données Données persistantes partagées Technologies :  recherche efficace  mises à jour fiables Requêtes Efficacité de l’accès Accès à des données - persistantes, - partagées, - résistantes aux pannes, - pouvant être accédées et mises à jour de façon concurrente par d’autres applications. Contraintes Exprimées dans le langage de définition de données. Langage de définition et de manipulation de données orienté utilisateurs : SQL.

Modèles de données Serveur Modèle du système dans l’esprit du client Modèle EA du client Modèle de tables du modèle EA Serveur Data Models Models are a cornerstone of design. Engineers build a model of a car to work out any details before putting it into production. In the same manner, system designers develop models to explore ideas and improve the understanding of the database design. Purpose of Models Models help communicate the concepts in people’s minds. They can be used to do the following: Communicate Categorize Describe Specify Investigate Evolve Analyze Imitate The objective is to produce a model that fits a multitude of these uses, can be understood by an end user, and contains sufficient detail for a developer to build a database system. Tables sur disques

STRUCTURE RELATIONNELLE . Forme normale d'une relation : 1FN : tous les attributs sont simples et la relation possède une clé primaire. 2FN : 1FN et tous les attributs non clé sont en DF élémentaire avec la clé. 3FN : 2FN et tous les attributs non clé sont en DF directe avec la clé. Ex. Dept( deptno , dname, loc ) est en 3FN . Une liaison 1,n et 1,1 entre 2 entités -> 2 relations en 3FN Dans un département, il y a n employés et 1 employé appartient à 1 seul département D’où les 2 relations en 3FN suivantes : Dept( deptno , dname, loc ) -- deptno est clef primaire Emp (empno,ename,job,mgr,hiredate,sal,comm,deptno ) -- deptno est clef étrangère . Une liaison m,n entre 2 entités -> 3 relations en 3FN Un livre peut être écrit par plusieurs auteurs et un auteur peut écrire plusieurs livres. On se ramène à 2 liaisons 1,n et 1,1 en utilisant une association Auteur_livre: Auteur( numauteur, nom ) -- numauteur est clef primaire Livre( numlivre, titre, nb_de_pages, editeur) -- numlivre est clef primaire Auteur_Livre(numauteur,numlivre) --ici(numauteur, numlivre)est clef primaire

ALGEBRE RELATIONNELLE . Cas d’une seule table PROJECTION : .(horizontale) on diminue le nombre de colonnes. select empno, ename from emp; SELECTION : .(verticale à l’aide de where) on diminue le nombre de lignes. select * from emp where deptno = 10; TRI : (order by) tri sur critère(en croissant(ASCENDING) par défaut). select * from emp order by empno; REGROUPEMENT : (group by) tri sur critère puis constitution de sous-groupes. select deptno from emp group by deptno; . Cas de 2 tables ou plus PRODUIT CARTESIEN : select * from emp, dept; Ø-JOINTURE où Ø € { ‘=’, ‘!=’, ‘<’ ‘<=’, ‘>’, ‘>=’ }. Ex. EQUI-JOINTURE où Ø = ‘=’ select * from emp e ,dept d where e.deptno = d.deptno; UNION , INTERSECTION et DIFFERENCE( avec des colonnes compatibles) : select coli, colj from table1 UNION (respectivement INTERSECT ou MINUS ) select colk, colm from table2;

Définition d’une Base de Données Relationnelle Une BD relationnelle est une collection de relations ou de tables bi-dimensionnelles BD EMPNO ENAME JOB DEPTNO 7839 KING PRESIDENT 10 7698 BLAKE MANAGER 30 7782 CLARK MANAGER 10 7566 JONES MANAGER 20 Nom de table : EMP DEPTNO DNAME LOC 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON Nom de table : DEPT Definition of a Relational Database A relational database uses relations or two-dimensional tables to store information. For example, you might want to store information about all the employees in your company. In a relational database, you create several tables to store different pieces of information about your employees, such as an employee table, a department table, and a salary table.

Lier plusieurs tables Chaque ligne dans une table est identifiée de façon unique par une clé primaire. Vous pouvez lier logiquement des données de plusieurs tables en utilisant les clés étrangères Nom de la table : EMP Nom de la table : DEPT EMPNO ENAME JOB DEPTNO 7839 KING PRESIDENT 10 7698 BLAKE MANAGER 30 7782 CLARK MANAGER 10 7566 JONES MANAGER 20 DEPTNO DNAME LOC 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON Relating Multiple Tables Each table contains data that describes exactly one entity. For example, the EMP table contains information about employees. Categories of data are listed across the top of each table, and individual cases are listed below. Using a table format, you can readily visualize, understand, and use information. Because data about different entities is stored in different tables, you may need to combine two or more tables to answer a particular question. For example, you may want to know the location of the department where an employee works. In this scenario, you need information from the EMP table (which contains data about employees) and the DEPT table (which contains information about departments). An RDBMS enables you to relate the data in one table to the data in another by using the foreign keys. A foreign key is a column or a set of columns that refer to a primary key in the same table or another table. The ability to relate data in one table to data in another enables you to organize information in separate, manageable units. Employee data can be kept logically distinct from department data by storing it in a separate table. Guidelines for Primary Keys and Foreign Keys No duplicate values are allowed in a primary key. Primary keys generally cannot be changed. Foreign keys are based on data values and are purely logical, not physical, pointers. A foreign key value must match an existing primary key value or unique key value, or else be null. Clé primaire Clé étrangère

Terminologie des BD relationnelles 2 3 4 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ------------- ------------ --------------------- -------- ---------------- ----------- -------------- ----------- 7839 KING PRESIDENT 17-NOV-81 5000 10 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 7782 CLARK MANAGER 7839 09-JUN-81 2450 10 7566 JONES MANAGER 7839 02-APR-81 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 7900 JAMES CLERK 7698 03-DEC-81 950 30 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 7902 FORD ANALYST 7566 03-DEC-81 3000 20 7369 SMITH CLERK 7902 17-DEC-80 800 20 7788 SCOTT ANALYST 7566 09-DEC-82 3000 20 7876 ADAMS CLERK 7788 12-JAN-83 1100 20 7934 MILLER CLERK 7782 23-JAN-82 1300 10 6 5 Terminology Used in a Relational Database A relational database can contain one or many tables. A table is the basic storage structure of an RDBMS. A table holds all the data necessary about something in the real world—for example, employees, invoices, or customers. The slide shows the contents of the EMP table or relation. The numbers indicate the following: 1. A single row or tuple representing all data required for a particular employee. Each row in a table should be identified by a primary key, which allows no duplicate rows. The order of rows is insignificant; specify the row order when the data is retrieved. 2. A column or attribute containing the employee number, which is also the primary key. The employee number identifies a unique employee in the EMP table. A primary key must contain a value. 3. A column that is not a key value. A column represents one kind of data in a table; in the example, the job title of all the employees. Column order is insignificant when storing data; specify the column order when the data is retrieved. 4. A column containing the department number, which is also a foreign key. A foreign key is a column that defines how tables relate to each other. A foreign key refers to a primary key or a unique key in another table. In the example, DEPTNO uniquely identifies a department in the DEPT table. 5. A field can be found at the intersection of a row and a column. There can be only one value in it. 6. A field may have no value in it. This is called a null value. In the EMP table, only employees who have a role of salesman have a value in the COMM (commission) field. Note: Null values are covered further in subsequent lessons. 1

Communiquer avec un SGBDR en utilisant SQL SQL> SELECT loc 2 FROM dept; Un ordre SQL est entré L’ordre est envoyé à la BD BD LOC ------------- NEW YORK DALLAS CHICAGO BOSTON Les données sont affichées Structured Query Language SQL allows you to communicate with the server and has the following advantages: Efficient Easy to learn and use Functionally complete (SQL allows you to define, retrieve, and manipulate data in the tables.)

SGBDR Serveur Tables utilisateur Dictionnaire des données Relational Database Management System Oracle provides a flexible RDBMS called Oracle7. Using its features, you can store and manage data with all the advantages of a relational structure plus PL/SQL, an engine that provides you with the ability to store and execute program units. The server offers the options of retrieving data based on optimization techniques. It includes security features that control how a database is accessed and used. Other features include consistency and protection of data through locking mechanisms. Oracle applications may run on the same computer as the Oracle Server. Alternatively, you can run applications on a system local to the user and run the Oracle Server on another system (client-server architecture). In this client-server environment, a wide range of computing resources can be used. For example, a form-based airline reservation application can run on a client personal computer while accessing flight data that is conveniently managed by an Oracle Server on a central computer. For more information, see Oracle Server Concepts Manual, Release 8. Tables utilisateur Dictionnaire des données

Solution Oracle Complète Applications Finance Fabrication ... Oracle Developer Discoverer Oracle Designer SQL PL/SQL SQL* Plus Oracle10G Database Dictionnaire des données Oracle Complete Solution The Oracle relational database management system is the Oracle core product. It includes the Oracle Server and several tools intended to assist the users in the maintenance, monitoring, and actual use of the data. The Oracle data dictionary is one of the most important components of the Server. It consists of a set of tables and views that provide a read-only reference to the database. The RDBMS handles tasks such as the following: Managing the storage and definition of data Controlling and restricting data access and concurrency Providing backup and recovery Interpreting SQL and PL/SQL statements Note: PL/SQL is an Oracle procedural language that extends SQL by adding application logic. SQL and PL/SQL statements are used by all programs and users to access and manipulate data stored in the Oracle database. Using application programs, you often can access the database without directly using SQL or PL/SQL, because you may press a button or select a check box, for example, but the applications implicitly use SQL or PL/SQL when executing the request. SQL*Plus is an Oracle tool that recognizes and submits SQL and PL/SQL statements to the server for execution and contains its own command language. Oracle offers a wide variety of state-of-the-art graphical, user interface (GUI) driven tools to build business applications as well as a large suite of software applications for many areas of business and industries. Note: More about the Oracle data dictionary is covered in subsequent lessons. Tables de données

ORDRES SQL SELECT INSERT UPDATE DELETE CREATE ALTER DROP RENAME TRUNCATE COMMIT ROLLBACK SAVEPOINT GRANT REVOKE Recherche de données Langage de manipulation de données (DML) Langage de définition de Données (DDL) Contrôle des transactions SQL Statements Oracle SQL complies with industry-accepted standards. Oracle Corporation ensures future compliance with evolving standards by actively involving key personnel in SQL standards committees. Industry-accepted committees are the American National Standards Institute (ANSI) and the International Standards Organization (ISO). Both ANSI and ISO have accepted SQL as the standard language for relational databases. Langage de contrôle des données (DCL)

Tables Utilisées dans le Cours EMP EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO --------- ---------- --------- --------- --------- --------- --------- --------- 7839 KING PRESIDENT 17-NOV-81 5000 10 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 7782 CLARK MANAGER 7839 09-JUN-81 2450 10 7566 JONES MANAGER 7839 02-APR-81 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 7900 JAMES CLERK 7698 03-DEC-81 950 30 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 7902 FORD ANALYST 7566 03-DEC-81 3000 20 7369 SMITH CLERK 7902 17-DEC-80 800 20 7788 SCOTT ANALYST 7566 09-DEC-82 3000 20 7876 ADAMS CLERK 7788 12-JAN-83 1100 20 7934 MILLER CLERK 7782 23-JAN-82 1300 10 DEPT DEPTNO DNAME LOC --------- -------------- ---------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON GRADE LOSAL HISAL --------- --------- --------- 1 700 1200 2 1201 1400 3 1401 2000 4 2001 3000 5 3001 9999 SALGRADE Tables Used in the Course The following three tables will be used in this course: EMP table, which gives details of all the employees DEPT table, which gives details of all the departments SALGRADE table, which gives details of salaries for various grades The structure and data for all the tables is given in Appendix B.

Interaction entre SQL and SQL*Plus SQL Statements Buffer SQL Statements Server SQL*Plus SQL*Plus Commands Query Results SQL and SQL*Plus SQL is a command language for communication with the Oracle Server from any tool or application. Oracle SQL contains many extensions. When you enter a SQL statement, it is stored in a part of memory called the SQL buffer and remains there until you enter a new statement. SQL*Plus is an Oracle tool that recognizes and submits SQL statements to the Oracle Server for execution and contains its own command language. Features of SQL Can be used by a range of users, including those with little or no programming experience Is a nonprocedural language Reduces the amount of time required for creating and maintaining systems Is an English-like language Features of SQL*Plus Accepts ad hoc entry of statements Accepts SQL input from files Provides a line editor for modifying SQL statements Controls environmental settings Formats query results into a basic report Accesses local and remote databases Formatted Report

Ordres SQL / Commandes SQL*Plus Un langage Standard ANSI Mots clés : pas d’abréviation Les ordres manipulent des définitions de données et de tables de la base de données SQL*Plus Un environnement Propriété d’Oracle Abréviation possible des mots clés Les commandes ne permettent pas la manipulation des valeurs de la base de données. SQL statements SQL buffer SQL*Plus commands SQL*Plus buffer SQL and SQL*Plus (continued) The following table compares SQL and SQL*Plus:

Aperçu de SQL*Plus Ouvrir une session SQL*Plus. Décrire la structure de la table. Éditer vos ordres SQL. Exécuter SQL à partir de SQL*Plus. Sauvegarder des ordres SQL dans des fichiers et ajouter des ordres SQL aux fichiers. Exécuter des fichiers sauvegardés. Charger des commandes à partir d’un fichier vers un buffer pour les éditer. SQL*Plus SQL*Plus is an environment in which you can do the following: Execute SQL statements to retrieve, modify, add, and remove data from the database Format, perform calculations on, store, and print query results in the form of reports Create script files to store SQL statements for repetitive use in the future SQL*Plus commands can be divided into the following main categories: Class Management Note (for Page 1-27) Snippet: “Establishing a Database Session” Logging in to SQL*Plus: Release number may vary, depending on the version installed.

Se connecter à SQL*Plus DIRECTEMENT sous sqlplus : Démarrer->programmes->oracle->sqlplus Ou sur le WEB par : http://iuta1.univ-lyon1.fr:5560/isqlplus Nom d’utilisateur : « prénom.nom » Mot de passe : « prénom.nom » Identificateur de connexion : iuta Logging In to SQL*Plus How you invoke SQL*Plus depends on which type of operating system or Windows environment you are running. To log in through a Windows environment: 1. Click Start—>Programs—>Oracle for Windows NT—>SQL*Plus 8.0. 2. Fill in username, password, and database. To log in through a command-line environment: 1. Log on to your machine. 2. Enter the SQL*Plus command as shown in the slide. In the command: username is your database username password is your database password (if you enter your password here, it is visible) @database is the database connect string Note: To ensure the integrity of your password, do not enter it at the operating system prompt. Instead, enter only your username. Enter your password at the Password prompt. Once you are successfully logged in to SQL*Plus, you see the following message: SQL*Plus : Release 8.0.3.0.0 - Production on Mon Oct 06 16:03:43 1997 (c) Copyright 1997 Oracle Corporation. All rights reserved.

Afficher la structure des tables Commande SQL*Plus : DESCRIBE DESC[RIBE] tablename Displaying Table Structure In SQL*Plus, you can display the structure of a table using the DESCRIBE command. The result of the command is to see the column names and datatypes as well as whether a column must contain data. In the syntax: tablename is the name of any existing table, view, or synonym accessible to the user

Afficher la structure des tables SQL> DESC dept Name Null? Type ----------------- -------- ------------ DEPTNO NOT NULL NUMBER(2) DNAME VARCHAR2(14) LOC VARCHAR2(13) Displaying Table Structure (continued) The example on the slide displays the information about the structure of the DEPT table. In the result: Null? indicates whether a column must contain data; NOT NULL indicates that a column must contain data Type displays the datatype for a column The datatypes are described in the following table: