base de données relationnelles - markito sanches · 24/02/2017 1 base de données relationnelles...
TRANSCRIPT
24/02/2017
1
Base de données relationnelles
Relational Database
Qu’est-ce qu’une base de données ?What is a database?
� C’est une :
� Collection de données, organisées sous forme de tables
� It's a :
� data collection, organized in tables
https://www.youtube.com/watch?v=t8jgX1f8kc4
https://www.youtube.com/watch?v=ia4eCxPPc_o
http://www.explania.com/fr/chaines/logiciels/detail/comment-fonctionne-une-base-de-donnees
24/02/2017
2
Les formes normalesNormal forms
� 1FN
� Pas de groupe répétitif dans la structure
� X � Y et non X � Y1 Y2 Y3 … Yn
� 2FN
� Dépendance fonctionnelle observée sur la totalité de la clé.
� X1X2 � Y où en réalité X1 � Y
� 3FN
� Aucune dépendance fonctionnelle observée parmi les attributs non clé de la structure
� Pas de X � Y1 � Y2
Les formes normalesNormal forms
� 1FN
� No repeating group in the structure
� X � Y and not X � Y1 Y2 Y3 ... Yn
� 2FN
� functional dependency observed on the whole key.
� X1X2 � Y where X1 reality � Y
� 3NF
� No functional dependency observed among non-key attributes of the structure
� No X � Y1 � Y2
24/02/2017
3
Première Forme Normale (1NF)First Normal Form (1NF)
� As per First Normal Form, no two Rows of data must contain repeating group of information i.e each set of column must have a unique value, such that multiple columns cannot be used to fetch the same row. Each table should be organized into rows, and each row should have a primary key that distinguishes it as unique.
� The Primary key is usually a single column, but sometimes more than one column can be combined to create a single primary key. For example consider a table which is not in First normal form
� In First Normal Form, any row must not have a column in which more than one value is saved, like separated with commas. Rather than that, we must separate such data into multiple row
Première Forme Normale (1NF)First Normal Form (1NF)
Student Age Subject
Adam 15 Biology, Maths
Alex 14 Maths
Stuart 17 Maths
Student Age Subject
Adam 15 Biology
Adam 15 Maths
Alex 14 Maths
Stuart 17 Maths
24/02/2017
4
Deuxième Forme Normale (2NF)Second Normal Form (2NF)
� As per the Second Normal Form there must not be any partial dependency of any column on primary key. It means that for a table that has concatenated primary key, each column in the table that is not part of the primary key must depend upon the entire concatenated key for its existence. If any column depends only on one part of the concatenated key, then the table fails Second normal form.
� In Subject Table the candidate key will be {Student, Subject} column. Now, both the above tables qualifies for Second Normal Form and will never suffer from Update Anomalies. Although there are a few complex cases in which table in Second Normal Form suffers Update Anomalies, and to handle those scenarios Third Normal Form is there
Deuxième Forme Normale (2NF)Second Normal Form (2NF)
Student Age
Adam 15
Alex 14
Stuart 17
Student Subject
Adam Biology
Adam Maths
Alex Maths
Stuart Maths
24/02/2017
5
Troisième Forme Normale (3NF)Third Normal Form (3NF)
� Third Normal form applies that every non-prime attribute of table must be dependent on primary key, or we can say that, there should not be the case that a non-prime attribute is determined by another non-prime attribute. So this transitive functional dependency should be removed from the table and also the table must be in Second Normal form. For example, consider a table with following fields.
� In this table Student is Primary key, country and state depends upon City. The dependency between city and other fields is called transitive dependency.
� The advantage of removing transtive dependency is,
� Amount of data duplication is reduced.
� Data integrity achieved.
Troisième Forme Normale (3NF)Third Normal Form (3NF)
http://www.studytonight.com/dbms/database-normalization.php
Student Age Address City State Country
Adam 16 Av St Catherine Montreal QC Canada
Alex 20 Des Jardins Montreal QC Canada
Stuart 23 Av. Sherbrooke Laval QC Canada
City State Country
Montreal QC Canada
Laval QC Canada
Student Age Address City
Adam 16 Av St Catherine Montreal
Alex 20 Des Jardins Montreal
Stuart 23 Av. Sherbrooke Laval
24/02/2017
6
Modélisation des donnéesData Modeling
� Règles et principes de modélisation
� Essentiellement, le modèle se compose de trois types d’objets :
� Des entités
� Des relations (associations)
� Des attributs
� Modeling rules and principles
� Essentially, the model consists of three types of objects:
� Entities
� Relationships (associations)
� Attributes
Modélisation des donnéesData Modeling
� Des entités
� Tout objet d'intérêt pour l'organisation sur lequel on doit conserver des informations.
� Représente un regroupement d'occurrences d'un seul et même type de chose.
� Chacune des occurrences doit être identifiable et distincte.
� Toutes les occurrences sont décrites par les mêmes caractéristiques.
� Identifiant :
� Valeur qui identifie de façon unique chacune des occurrences de l'entité, tel que perçu par l'utilisateur.
� Généralement composé d'un seul attribut, mais peut être composé de plusieurs.
� Dans un modèle, chaque entité possède un identifiant distinct des autres entités.
24/02/2017
7
Modélisation des donnéesData Modeling
� Entities
� Any object of interest to the organization on which information is to be kept.
� Represents a grouping of occurrences of one and the same type of thing.
� Each occurrence must be identifiable and distinct.
� All occurrences are described by the same characteristics.
� Identity(ID)
� A value that uniquely identifies each occurrence of the entity as perceived by the user.
� Generally composed of a single attribute, but can be composed of several.
� In a model, each entity has an identifier distinct from the other entities.
Modélisation des donnéesData Modeling
� Des relations (associations)
� Un lien perçu dans la réalité entre deux entités.
� La relation n'a pas d'existence propre.
� Types de relations:
� Zero - Un
� Un – Un
� Zero – Plusieurs
� Un – Plusieurs
� Plusieurs - Plusieurs
24/02/2017
8
Modélisation des donnéesData Modeling
� Relationships (associations)
� A perceived link between two entities.
� The relationship has no existence of its own.
� Types of relationships:
� Zero one
� One – One
� Zero – Many
� One - Many
� Many - Many
Modélisation des donnéesData Modeling
� Les attributs
� La position d'un attribut dans une entité doit satisfaire aux trois formes normales.
� La gamme de valeurs
� Un type de données (standard) avec sa longueur autorisée.
� Liste des valeurs autorisées.
� Règles qui définissent valide.
� Apparence facultative ou obligatoire.
� Valeur par défaut (le cas échéant).
24/02/2017
9
Modélisation des donnéesData Modeling
� Attributes
� The position of an attribute in an entity must meet the three normal forms.
� The range of values
� A data type (standard) with its length permitted.
� A list of allowed values.
� The rules that define valid.
� The optional or mandatory appearance.
� The default value (if any).
MySQL Data Types - Text typesData type Description
CHAR(size)Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. Can store up to 255 characters
VARCHAR(size)
Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis. Can store up to 255 characters. Note: If you put a greater value than 255 it will be converted to a TEXT type
TINYTEXT Holds a string with a maximum length of 255 characters
TEXT Holds a string with a maximum length of 65,535 characters
BLOBFor BLOBs (Binary Large OBjects). Holds up to 65,535 bytes of data
MEDIUMTEXT Holds a string with a maximum length of 16,777,215 characters
24/02/2017
10
MySQL Data Types - Text typesData type Description
MEDIUMBLOBFor BLOBs (Binary Large OBjects). Holds up to 16,777,215 bytes of data
LONGTEXTHolds a string with a maximum length of 4,294,967,295 characters
LONGBLOBFor BLOBs (Binary Large OBjects). Holds up to 4,294,967,295 bytes of data
ENUM(x,y,z,etc.)
Let you enter a list of possible values. You can list up to 65535 values in an ENUM list. If a value is inserted that is not in the list, a blank value will be inserted.Note: The values are sorted in the order you enter them.You enter the possible values in this format: ENUM('X','Y','Z')
SETSimilar to ENUM except that SET may contain up to 64 list items and can store more than one choice
MySQL Data Types - Number typesData type Description
TINYINT(size)-128 to 127 normal. 0 to 255 UNSIGNED*. The maximum number of digits may be specified in parenthesis
SMALLINT(size)-32768 to 32767 normal. 0 to 65535 UNSIGNED*. The maximum number of digits may be specified in parenthesis
MEDIUMINT(size)-8388608 to 8388607 normal. 0 to 16777215 UNSIGNED*. The maximum number of digits may be specified in parenthesis
INT(size)-2147483648 to 2147483647 normal. 0 to 4294967295 UNSIGNED*. The maximum number of digits may be specified in parenthesis
24/02/2017
11
MySQL Data Types - Number typesData type Description
FLOAT(size,d)
A small number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter
DOUBLE(size,d)
A large number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter
DECIMAL(size,d)
A DOUBLE stored as a string , allowing for a fixed decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter
FLOAT(size,d)
A small number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter
MySQL Data Types – Date TypesData type Description
DATE()A date. Format: YYYY-MM-DDNote: The supported range is from '1000-01-01' to '9999-12-31'
DATETIME()*A date and time combination. Format: YYYY-MM-DD HH:MI:SSNote: The supported range is from '1000-01-01 00:00:00' to '9999-12-31 23:59:59'
TIMESTAMP()
*A timestamp. TIMESTAMP values are stored as the number of seconds since the Unix epoch ('1970-01-01 00:00:00' UTC). Format: YYYY-MM-DD HH:MI:SSNote: The supported range is from '1970-01-01 00:00:01' UTC to '2038-01-09 03:14:07' UTC
TIME()A time. Format: HH:MI:SSNote: The supported range is from '-838:59:59' to '838:59:59'
24/02/2017
12
MySQL Data Types – Date TypesData type Description
TIME()A time. Format: HH:MI:SSNote: The supported range is from '-838:59:59' to '838:59:59'
YEAR()A year in two-digit or four-digit format.Note: Values allowed in four-digit format: 1901 to 2155. Values allowed in two-digit format: 70 to 69, representing years from 1970 to 2069
Modèle Entité-RelationEntity-Relationship Model(ER)
� Un modèle de relation d'entité, également appelé diagramme d'entité-relation (ER), est une représentation graphique des entités et de leurs relations avec les autres, généralement utilisées dans la representation de l'organisation des données dans des bases de données ou des systèmes d'information.
� An entity relationship model, also called an entity-relationship (ER)
diagram, is a graphical representation of entities and their relationships to
each other, typically used in computing in regard to the organization of data
within databases or information systems.
24/02/2017
13
Modèle Entité-RelationEntity-Relationship Model(ER)
� Formalismes Relationnel (Relationnel Formalisms).
� Crow's feet
� Zero - One
� One - Many
� One - One
� One - Many