SlideShare ist ein Scribd-Unternehmen logo
1 von 47
Database Modeling
Creating E/R Diagrams with SQL Server
Management Studio and MySQLWorkbench
Svetlin Nakov
Telerik Software Academy
http://academy.telerik.com
ManagerTechnicalTraining
http://nakov.com
Table of Contents
1. Data Modeling – Principles
2. DataTypes in SQL Server
3. Creating Databases in SQL Server
4. CreatingTables
5. Defining a Primary Key and Identity Columns
6. Creating Relationships between theTables
 One-to-many, Many-to-many, One-to-one
7. Naming Conventions
8. Data Modeling in MySQL Workbench
2
Relational Data Modeling
Fundamental Concepts
Steps in Database Design
 Steps in the database design process:
1. Identification of the entities
2. Identification of the columns in the tables
3. Defining a primary key for each entity table
4. Identification and modeling of relationships
 Multiplicity of relationships
5. Defining other constraints
6. Filling test data in the tables
4
Identification of Entities
 Entity tables represent objects from the real
world
 Most often they are nouns in the specification
 For example:
 Entities: Student, Course,Town
5
We need to develop a system that stores information
about students, which are trained in various courses.
The courses are held in different towns. When
registering a new student the following information is
entered: name, faculty number, photo and date.
Identification of Columns
 Columns in the tables are characteristics of the
entities
 They have name and type
 For example students have:
 Name (text)
 Faculty number (number)
 Photo (binary block)
 Date of enlistment (date)
6
Identification of the Columns
 Columns are clarifications for the entities in
the text of the specification, for example:
 Students have the following characteristics:
 Name, faculty number, photo, date of
enlistment and a list of courses they visit
7
We need to develop a system that stores information
about students, which are trained in various courses.
The courses are held in different towns. When
registering a new student the following information is
entered: name, faculty number, photo and date.
How to Choose a Primary Key?
 Always define an additional column for the
primary key
 Don't use an existing column (for example SSN)
 Must be an integer number
 Must be declared as a primary key
 Use identity to implement auto-increment
 Put the primary key as a first column
 Exceptions
 Entities that have well known ID, e.g. countries
(BG, DE, US) and currencies (USD, EUR, BGN)
8
Identification of Relationships
 Relationships are dependencies between the
entities:
 "Students are trained in courses" – many-to-
many relationship
 "Courses are held in towns" – many-to-one (or
many-to-many) relationship
9
We need to develop a system that stores information
about students, which are trained in various courses.
The courses are held in different towns. When
registering a new student the following information is
entered: name, faculty number, photo and date.
DataTypes in SQL
Server 2012
DataTypes in SQL Server
 Numeric
 bit (1-bit), integer (32-bit), bigint (64-bit)
 float, real, numeric(scale, precision)
 money – for money (precise) operations
 Strings
 char(size) – fixed size string
 varchar(size) – variable size string
 nvarchar(size) – Unicode variable size string
 text / ntext – text data block (unlimited size)
11
DataTypes in SQL Server (2)
 Binary data
 varbinary(size) – a sequence of bits
 image – a binary block up to 1 GB
 Date and time
 datetime – date and time starting from
1.1.1753 to 31.12. 9999, a precision of 1/300 sec.
 smalldatetime – date and time (1-minute
precision)
12
DataTypes in SQL Server (3)
 Other types
 timestamp – automatically generated number
whenever a change is made to the data row
 uniqueidentifier – GUID identifier
 xml – data in XML format
13
DataTypes in SQL Server (4)
 Nullable and NOT NULL types
 All types in SQL Server may or may
not allow NULL values
 Primary key columns
 Define the primary key
 Identity columns
 Automatically increased values when a new row
is inserted (auto-increment values)
 Used in combination with primary key
14
Database Modeling with SQL
Server Management Studio
Creating Database
Connecting to SQL Server
 When starting SSMS a window pops up
 Usually it is enough to just click the "Connect"
button without changing anything
16
Working with Object Explorer
 Object Explorer is the main tool to use when
working with the database and its objects
 Enables us:
 To create a new database
 To create objects in the database (tables, stored
procedures, relationships and others)
 To change the properties of objects
 To enter records into the tables
17
Creating a New Database
 In Object Explorer we go to the "Databases" and
choose "New Database…" from the context menu
18
Creating a New Database (2)
 In the "New Database" window enter the name of
the new database and click [OK]
19
Database Modeling with SQL
Server Management Studio
Creating E/R Diagrams
Creating an E/R diagram
 In the "Database Diagrams" menu choose the
"New Database Diagram"
 We can choose from the existing tables, which we
want to add to the diagram
21
Database Modeling with SQL
Server Management Studio
CreatingTables
CreatingTables
 If the database doesn't show immediately in
Object Explorer perform "Refresh" [F5]
 Creating new table:
23
CreatingTables (2)
 Enter table name and define the table
columns (name and type):
24
Enter the
name of the
column here
Choose the data
type of the
column here
Choose
whether NULLs
are allowed
CreatingTables (3)
 Defining a primary key
25
Right click on the
column start and select
"Set Primary Key"
CreatingTables (4)
 Defining an identity columns
 Identity means that the values in a certain
column are auto generated (for int columns)
 These values cannot be assigned manually
 Identity Seed – the starting number from which
the values in the column begin to increase.
 Identity Increment – by how much each
consecutive value is increased
26
CreatingTables (5)
 Setting an identity through the "Column
Properties" window
27
CreatingTables (6)
 It is a good practice to set
the name of the table at
the time it is created
 Use the "Properties" window
 If it's not visible use "View"
 "Properties Window" or
press [F4]
28
Table
name
CreatingTables (7)
 When closing the window for the table, SSMS
asks whether to save the table
 You can do it manually by choosing “SaveTable”
from the “File” menu or by pressing Ctrl + S
29
Database Modeling with SQL
Server Management Studio
Creating Relationships between Tables
Creating Relationships
 To create one-to-many relationship drag the
foreign key column onto the other table
 Drag from the child table to the parent table
31
Self-Relationships
 Self-relationship can be created by dragging a
foreign key onto the same table
32
Database Modeling with SQL
Server Management Studio
Naming Conventions
Naming Conventions
 Tables
 Each word is capitalized (Pascal Case)
 In English, plural
 Examples: Users, PhotoAlbums, Countries
 Columns
 In English, singular
 Each word is capitalized (Pascal Case)
 Avoid reserved words (e.g. key, int, date)
 Examples: FirstName, OrderDate, Price
34
Naming Conventions (2)
 Primary key
 Use "Id" or name_of_the_table + "Id"
 Example: in the Users table the PK column
should be be called Id or UserId
 Foreign key
 Use the name of the referenced table + "Id"
 Example: in the Users table the foreign key
column that references the Groups table should
be named GroupId
35
Naming Conventions (3)
 Relationship names (constraints)
 In English, Pascal Case
 "FK_" + table1 + "_" + table2
 For example: FK_Users_Groups
 Index names
 "IX_" + table + column
 For example: IX_Users_UserName
36
Naming Conventions (4)
 Unique key constraints names
 "UK_" + table + column
 For instance: UK_Users_UserName
 Views names
 V_ + name
 Example: V_BGCompanies
 Stored procedures names
 usp_ + name
 Example: usp_InsertCustomer(@name)
37
Database Modeling with SQL
Server Management Studio
Live Demo
Data Modeling in MySQL
Creating E/R Diagrams with MySQLWorkbench
E/R Diagrams in
MySQL Workbench
 MySQL Workbench supports database schema
design (E/R diagrams)
 Can reverse engineer an existing database
 Can forward engineer the diagram into SQL
script / existing / new database
 Can synchronize schema changes with existing
database
 User-unfriendly UI but better than nothing
 Edit tables, relationships, indices, triggers, …
40
Data Modeling in MySQL
Live Demo
форумпрограмиране,форум уеб дизайн
курсовеи уроци по програмиране,уеб дизайн – безплатно
програмиранеза деца – безплатни курсове и уроци
безплатенSEO курс -оптимизация за търсачки
уроципо уеб дизайн, HTML,CSS, JavaScript,Photoshop
уроципо програмиранеи уеб дизайн за ученици
ASP.NETMVCкурс – HTML,SQL,C#,.NET,ASP.NETMVC
безплатенкурс"Разработка на софтуер в cloud среда"
BGCoder -онлайн състезателна система -online judge
курсовеи уроци по програмиране,книги – безплатно отНаков
безплатенкурс"Качествен програменкод"
алгоакадемия – състезателно програмиране,състезания
ASP.NETкурс -уеб програмиране,бази данни, C#,.NET,ASP.NET
курсовеи уроци по програмиране– Телерик академия
курсмобилни приложения с iPhone, Android,WP7,PhoneGap
freeC#book, безплатна книга C#,книга Java,книга C#
Дончо Минков -сайт за програмиране
Николай Костов -блог за програмиране
C#курс,програмиране,безплатно
Database Modeling
http://academy.telerik.com
Exercises
1. Create the following database diagram in SQL
Server:
2. Fill some sample data in the tables with SQL Server
Management Studio.
43
Exercises (2)
3. Typical universities have: faculties, departments,
professors, students, courses, etc. Faculties have
name and could have several departments. Each
department has name, professors and courses. Each
professor has name, a set of titles (Ph. D,
academician, senior assistant, etc.) and a set of
courses. Each course consists of several students.
Each student belongs to some faculty and to several
of the courses.Your task is to create a data model
(E/R diagram) for the typical university in SQL Server
using SQL Server Management Studio (SSMS).
4. Create the same data model in MySQL.
44
Exercises (3)
5. We should design a multilingual dictionary. We have
a set of words in the dictionary.
Each word can be in some language and can have
synonyms and explanations in the same language
and translation words and explanations in several
other languages.
The synonyms and translation words are sets of
words from the dictionary.The explanations are
textual descriptions.
Design a database schema (a set of tables and
relationships) to store the dictionary.
45
Exercises (4)
6. Add support in the previous database for storing
antonym pairs.
Add support for storing part-of-speech information
(e.g. verb, noun, adjective, …).
Add support for storing hypernym / hyponym chains
(e.g. tree  oak, pine, walnut-tree, …).
46
FreeTrainings @Telerik Academy
 C# Programming @Telerik Academy
 csharpfundamentals.telerik.com
 Telerik Software Academy
 academy.telerik.com
 Telerik Academy @ Facebook
 facebook.com/TelerikAcademy
 Telerik Software Academy Forums
 forums.academy.telerik.com

Weitere ähnliche Inhalte

Was ist angesagt?

Microsoft Access 2007: Get To Know Access
Microsoft Access 2007: Get To Know AccessMicrosoft Access 2007: Get To Know Access
Microsoft Access 2007: Get To Know Accessomoviejohn
 
Intro to Microsoft Access
Intro to Microsoft AccessIntro to Microsoft Access
Intro to Microsoft AccessDUSPviz
 
Microsoft Access 2007
Microsoft Access 2007Microsoft Access 2007
Microsoft Access 2007Reshma Arun
 
MS Office Access Tutorial
MS Office Access TutorialMS Office Access Tutorial
MS Office Access TutorialvirtualMaryam
 
Introduction to microsoft access
Introduction to microsoft accessIntroduction to microsoft access
Introduction to microsoft accessHardik Patel
 
MS Access teaching powerpoint tasks
MS Access teaching powerpoint tasksMS Access teaching powerpoint tasks
MS Access teaching powerpoint tasksskomadina
 
Microsoft Access Notes 2007 Ecdl
Microsoft Access Notes 2007 EcdlMicrosoft Access Notes 2007 Ecdl
Microsoft Access Notes 2007 EcdlRichard Butler
 
Access2003
Access2003Access2003
Access2003mrh1222
 
Defining Table Relationships
Defining Table RelationshipsDefining Table Relationships
Defining Table RelationshipsIIUI
 
Ms access Database
Ms access DatabaseMs access Database
Ms access DatabaseYasir Khan
 
Ms access notes
Ms access notesMs access notes
Ms access notesIKIARA
 

Was ist angesagt? (19)

Sq lite module8
Sq lite module8Sq lite module8
Sq lite module8
 
Microsoft Access 2007: Get To Know Access
Microsoft Access 2007: Get To Know AccessMicrosoft Access 2007: Get To Know Access
Microsoft Access 2007: Get To Know Access
 
Intro to Microsoft Access
Intro to Microsoft AccessIntro to Microsoft Access
Intro to Microsoft Access
 
Sq lite module6
Sq lite module6Sq lite module6
Sq lite module6
 
MS Access Training
MS Access TrainingMS Access Training
MS Access Training
 
Microsoft Access 2007
Microsoft Access 2007Microsoft Access 2007
Microsoft Access 2007
 
MS Office Access Tutorial
MS Office Access TutorialMS Office Access Tutorial
MS Office Access Tutorial
 
01 Microsoft Access
01 Microsoft Access01 Microsoft Access
01 Microsoft Access
 
Introduction to microsoft access
Introduction to microsoft accessIntroduction to microsoft access
Introduction to microsoft access
 
MS Access teaching powerpoint tasks
MS Access teaching powerpoint tasksMS Access teaching powerpoint tasks
MS Access teaching powerpoint tasks
 
Microsoft Access Notes 2007 Ecdl
Microsoft Access Notes 2007 EcdlMicrosoft Access Notes 2007 Ecdl
Microsoft Access Notes 2007 Ecdl
 
Uses of MS Access in Business
Uses of MS Access in BusinessUses of MS Access in Business
Uses of MS Access in Business
 
Access2003
Access2003Access2003
Access2003
 
Ms access
Ms accessMs access
Ms access
 
Excel Crash Course
Excel Crash CourseExcel Crash Course
Excel Crash Course
 
Ms access
Ms accessMs access
Ms access
 
Defining Table Relationships
Defining Table RelationshipsDefining Table Relationships
Defining Table Relationships
 
Ms access Database
Ms access DatabaseMs access Database
Ms access Database
 
Ms access notes
Ms access notesMs access notes
Ms access notes
 

Ähnlich wie 01 data modeling-and-er-diagrams

Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docxLab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docxVinaOconner450
 
MS SQL SERVER: Using the data mining tools
MS SQL SERVER: Using the data mining toolsMS SQL SERVER: Using the data mining tools
MS SQL SERVER: Using the data mining toolsDataminingTools Inc
 
MS SQL SERVER: Using the data mining tools
MS SQL SERVER: Using the data mining toolsMS SQL SERVER: Using the data mining tools
MS SQL SERVER: Using the data mining toolssqlserver content
 
Analysis Services en SQL Server 2008
Analysis Services en SQL Server 2008Analysis Services en SQL Server 2008
Analysis Services en SQL Server 2008Eduardo Castro
 
SQL Server Denali: BI on Your Terms
SQL Server Denali: BI on Your Terms SQL Server Denali: BI on Your Terms
SQL Server Denali: BI on Your Terms Andrew Brust
 
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docxLab 2 Work with Dictionary and Create Relational Database (60 pts.docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docxDIPESH30
 
Access Basics 01
Access Basics 01Access Basics 01
Access Basics 01Lets try
 
Sap bo 4.2 course content (1)
Sap bo 4.2 course content (1)Sap bo 4.2 course content (1)
Sap bo 4.2 course content (1)vamshireddy kunta
 
It203 class slides-unit5
It203 class slides-unit5It203 class slides-unit5
It203 class slides-unit5Matthew Moldvan
 
DSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BI
DSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BI
DSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIEzekielJames8
 
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!Amanda Lam
 
MSBI and Data WareHouse techniques by Quontra
MSBI and Data WareHouse techniques by Quontra MSBI and Data WareHouse techniques by Quontra
MSBI and Data WareHouse techniques by Quontra QUONTRASOLUTIONS
 
Basics of Microsoft Business Intelligence and Data Integration Techniques
Basics of Microsoft Business Intelligence and Data Integration TechniquesBasics of Microsoft Business Intelligence and Data Integration Techniques
Basics of Microsoft Business Intelligence and Data Integration TechniquesValmik Potbhare
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developerAhsan Kabir
 
Introduction to database with ms access.hetvii
Introduction to database with ms access.hetviiIntroduction to database with ms access.hetvii
Introduction to database with ms access.hetvii07HetviBhagat
 

Ähnlich wie 01 data modeling-and-er-diagrams (20)

Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docxLab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
 
MS SQL SERVER: Using the data mining tools
MS SQL SERVER: Using the data mining toolsMS SQL SERVER: Using the data mining tools
MS SQL SERVER: Using the data mining tools
 
MS SQL SERVER: Using the data mining tools
MS SQL SERVER: Using the data mining toolsMS SQL SERVER: Using the data mining tools
MS SQL SERVER: Using the data mining tools
 
Analysis Services en SQL Server 2008
Analysis Services en SQL Server 2008Analysis Services en SQL Server 2008
Analysis Services en SQL Server 2008
 
SQL Server Denali: BI on Your Terms
SQL Server Denali: BI on Your Terms SQL Server Denali: BI on Your Terms
SQL Server Denali: BI on Your Terms
 
Spss basics tutorial
Spss basics tutorialSpss basics tutorial
Spss basics tutorial
 
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docxLab 2 Work with Dictionary and Create Relational Database (60 pts.docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docx
 
Access Basics 01
Access Basics 01Access Basics 01
Access Basics 01
 
7. SQL.pptx
7. SQL.pptx7. SQL.pptx
7. SQL.pptx
 
Microsoft excel
Microsoft excelMicrosoft excel
Microsoft excel
 
Sap bo 4.2 course content (1)
Sap bo 4.2 course content (1)Sap bo 4.2 course content (1)
Sap bo 4.2 course content (1)
 
Metadata Creation In OBIEE
Metadata Creation In OBIEEMetadata Creation In OBIEE
Metadata Creation In OBIEE
 
It203 class slides-unit5
It203 class slides-unit5It203 class slides-unit5
It203 class slides-unit5
 
Fg d
Fg dFg d
Fg d
 
DSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BI
DSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BI
DSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BIDSN_Power BI
 
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
Waiting too long for Excel's VLOOKUP? Use SQLite for simple data analysis!
 
MSBI and Data WareHouse techniques by Quontra
MSBI and Data WareHouse techniques by Quontra MSBI and Data WareHouse techniques by Quontra
MSBI and Data WareHouse techniques by Quontra
 
Basics of Microsoft Business Intelligence and Data Integration Techniques
Basics of Microsoft Business Intelligence and Data Integration TechniquesBasics of Microsoft Business Intelligence and Data Integration Techniques
Basics of Microsoft Business Intelligence and Data Integration Techniques
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
 
Introduction to database with ms access.hetvii
Introduction to database with ms access.hetviiIntroduction to database with ms access.hetvii
Introduction to database with ms access.hetvii
 

Mehr von glubox

06 xml processing-in-.net
06 xml processing-in-.net06 xml processing-in-.net
06 xml processing-in-.netglubox
 
05 entity framework
05 entity framework05 entity framework
05 entity frameworkglubox
 
Sql intro
Sql introSql intro
Sql introglubox
 
Bs business plan
Bs business planBs business plan
Bs business planglubox
 
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 2972032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29glubox
 
Tz Dch500
Tz Dch500Tz Dch500
Tz Dch500glubox
 
Tz Dch500
Tz Dch500Tz Dch500
Tz Dch500glubox
 
Tz Dch500
Tz Dch500Tz Dch500
Tz Dch500glubox
 
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 2972032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29glubox
 
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 2972032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29glubox
 
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 2972032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29glubox
 

Mehr von glubox (11)

06 xml processing-in-.net
06 xml processing-in-.net06 xml processing-in-.net
06 xml processing-in-.net
 
05 entity framework
05 entity framework05 entity framework
05 entity framework
 
Sql intro
Sql introSql intro
Sql intro
 
Bs business plan
Bs business planBs business plan
Bs business plan
 
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 2972032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
 
Tz Dch500
Tz Dch500Tz Dch500
Tz Dch500
 
Tz Dch500
Tz Dch500Tz Dch500
Tz Dch500
 
Tz Dch500
Tz Dch500Tz Dch500
Tz Dch500
 
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 2972032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
 
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 2972032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
 
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 2972032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
72032 1 844 Hvr Hd250f 160f 28b Manu200239 02 29
 

Kürzlich hochgeladen

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 

Kürzlich hochgeladen (20)

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 

01 data modeling-and-er-diagrams

  • 1. Database Modeling Creating E/R Diagrams with SQL Server Management Studio and MySQLWorkbench Svetlin Nakov Telerik Software Academy http://academy.telerik.com ManagerTechnicalTraining http://nakov.com
  • 2. Table of Contents 1. Data Modeling – Principles 2. DataTypes in SQL Server 3. Creating Databases in SQL Server 4. CreatingTables 5. Defining a Primary Key and Identity Columns 6. Creating Relationships between theTables  One-to-many, Many-to-many, One-to-one 7. Naming Conventions 8. Data Modeling in MySQL Workbench 2
  • 4. Steps in Database Design  Steps in the database design process: 1. Identification of the entities 2. Identification of the columns in the tables 3. Defining a primary key for each entity table 4. Identification and modeling of relationships  Multiplicity of relationships 5. Defining other constraints 6. Filling test data in the tables 4
  • 5. Identification of Entities  Entity tables represent objects from the real world  Most often they are nouns in the specification  For example:  Entities: Student, Course,Town 5 We need to develop a system that stores information about students, which are trained in various courses. The courses are held in different towns. When registering a new student the following information is entered: name, faculty number, photo and date.
  • 6. Identification of Columns  Columns in the tables are characteristics of the entities  They have name and type  For example students have:  Name (text)  Faculty number (number)  Photo (binary block)  Date of enlistment (date) 6
  • 7. Identification of the Columns  Columns are clarifications for the entities in the text of the specification, for example:  Students have the following characteristics:  Name, faculty number, photo, date of enlistment and a list of courses they visit 7 We need to develop a system that stores information about students, which are trained in various courses. The courses are held in different towns. When registering a new student the following information is entered: name, faculty number, photo and date.
  • 8. How to Choose a Primary Key?  Always define an additional column for the primary key  Don't use an existing column (for example SSN)  Must be an integer number  Must be declared as a primary key  Use identity to implement auto-increment  Put the primary key as a first column  Exceptions  Entities that have well known ID, e.g. countries (BG, DE, US) and currencies (USD, EUR, BGN) 8
  • 9. Identification of Relationships  Relationships are dependencies between the entities:  "Students are trained in courses" – many-to- many relationship  "Courses are held in towns" – many-to-one (or many-to-many) relationship 9 We need to develop a system that stores information about students, which are trained in various courses. The courses are held in different towns. When registering a new student the following information is entered: name, faculty number, photo and date.
  • 11. DataTypes in SQL Server  Numeric  bit (1-bit), integer (32-bit), bigint (64-bit)  float, real, numeric(scale, precision)  money – for money (precise) operations  Strings  char(size) – fixed size string  varchar(size) – variable size string  nvarchar(size) – Unicode variable size string  text / ntext – text data block (unlimited size) 11
  • 12. DataTypes in SQL Server (2)  Binary data  varbinary(size) – a sequence of bits  image – a binary block up to 1 GB  Date and time  datetime – date and time starting from 1.1.1753 to 31.12. 9999, a precision of 1/300 sec.  smalldatetime – date and time (1-minute precision) 12
  • 13. DataTypes in SQL Server (3)  Other types  timestamp – automatically generated number whenever a change is made to the data row  uniqueidentifier – GUID identifier  xml – data in XML format 13
  • 14. DataTypes in SQL Server (4)  Nullable and NOT NULL types  All types in SQL Server may or may not allow NULL values  Primary key columns  Define the primary key  Identity columns  Automatically increased values when a new row is inserted (auto-increment values)  Used in combination with primary key 14
  • 15. Database Modeling with SQL Server Management Studio Creating Database
  • 16. Connecting to SQL Server  When starting SSMS a window pops up  Usually it is enough to just click the "Connect" button without changing anything 16
  • 17. Working with Object Explorer  Object Explorer is the main tool to use when working with the database and its objects  Enables us:  To create a new database  To create objects in the database (tables, stored procedures, relationships and others)  To change the properties of objects  To enter records into the tables 17
  • 18. Creating a New Database  In Object Explorer we go to the "Databases" and choose "New Database…" from the context menu 18
  • 19. Creating a New Database (2)  In the "New Database" window enter the name of the new database and click [OK] 19
  • 20. Database Modeling with SQL Server Management Studio Creating E/R Diagrams
  • 21. Creating an E/R diagram  In the "Database Diagrams" menu choose the "New Database Diagram"  We can choose from the existing tables, which we want to add to the diagram 21
  • 22. Database Modeling with SQL Server Management Studio CreatingTables
  • 23. CreatingTables  If the database doesn't show immediately in Object Explorer perform "Refresh" [F5]  Creating new table: 23
  • 24. CreatingTables (2)  Enter table name and define the table columns (name and type): 24 Enter the name of the column here Choose the data type of the column here Choose whether NULLs are allowed
  • 25. CreatingTables (3)  Defining a primary key 25 Right click on the column start and select "Set Primary Key"
  • 26. CreatingTables (4)  Defining an identity columns  Identity means that the values in a certain column are auto generated (for int columns)  These values cannot be assigned manually  Identity Seed – the starting number from which the values in the column begin to increase.  Identity Increment – by how much each consecutive value is increased 26
  • 27. CreatingTables (5)  Setting an identity through the "Column Properties" window 27
  • 28. CreatingTables (6)  It is a good practice to set the name of the table at the time it is created  Use the "Properties" window  If it's not visible use "View"  "Properties Window" or press [F4] 28 Table name
  • 29. CreatingTables (7)  When closing the window for the table, SSMS asks whether to save the table  You can do it manually by choosing “SaveTable” from the “File” menu or by pressing Ctrl + S 29
  • 30. Database Modeling with SQL Server Management Studio Creating Relationships between Tables
  • 31. Creating Relationships  To create one-to-many relationship drag the foreign key column onto the other table  Drag from the child table to the parent table 31
  • 32. Self-Relationships  Self-relationship can be created by dragging a foreign key onto the same table 32
  • 33. Database Modeling with SQL Server Management Studio Naming Conventions
  • 34. Naming Conventions  Tables  Each word is capitalized (Pascal Case)  In English, plural  Examples: Users, PhotoAlbums, Countries  Columns  In English, singular  Each word is capitalized (Pascal Case)  Avoid reserved words (e.g. key, int, date)  Examples: FirstName, OrderDate, Price 34
  • 35. Naming Conventions (2)  Primary key  Use "Id" or name_of_the_table + "Id"  Example: in the Users table the PK column should be be called Id or UserId  Foreign key  Use the name of the referenced table + "Id"  Example: in the Users table the foreign key column that references the Groups table should be named GroupId 35
  • 36. Naming Conventions (3)  Relationship names (constraints)  In English, Pascal Case  "FK_" + table1 + "_" + table2  For example: FK_Users_Groups  Index names  "IX_" + table + column  For example: IX_Users_UserName 36
  • 37. Naming Conventions (4)  Unique key constraints names  "UK_" + table + column  For instance: UK_Users_UserName  Views names  V_ + name  Example: V_BGCompanies  Stored procedures names  usp_ + name  Example: usp_InsertCustomer(@name) 37
  • 38. Database Modeling with SQL Server Management Studio Live Demo
  • 39. Data Modeling in MySQL Creating E/R Diagrams with MySQLWorkbench
  • 40. E/R Diagrams in MySQL Workbench  MySQL Workbench supports database schema design (E/R diagrams)  Can reverse engineer an existing database  Can forward engineer the diagram into SQL script / existing / new database  Can synchronize schema changes with existing database  User-unfriendly UI but better than nothing  Edit tables, relationships, indices, triggers, … 40
  • 41. Data Modeling in MySQL Live Demo
  • 42. форумпрограмиране,форум уеб дизайн курсовеи уроци по програмиране,уеб дизайн – безплатно програмиранеза деца – безплатни курсове и уроци безплатенSEO курс -оптимизация за търсачки уроципо уеб дизайн, HTML,CSS, JavaScript,Photoshop уроципо програмиранеи уеб дизайн за ученици ASP.NETMVCкурс – HTML,SQL,C#,.NET,ASP.NETMVC безплатенкурс"Разработка на софтуер в cloud среда" BGCoder -онлайн състезателна система -online judge курсовеи уроци по програмиране,книги – безплатно отНаков безплатенкурс"Качествен програменкод" алгоакадемия – състезателно програмиране,състезания ASP.NETкурс -уеб програмиране,бази данни, C#,.NET,ASP.NET курсовеи уроци по програмиране– Телерик академия курсмобилни приложения с iPhone, Android,WP7,PhoneGap freeC#book, безплатна книга C#,книга Java,книга C# Дончо Минков -сайт за програмиране Николай Костов -блог за програмиране C#курс,програмиране,безплатно Database Modeling http://academy.telerik.com
  • 43. Exercises 1. Create the following database diagram in SQL Server: 2. Fill some sample data in the tables with SQL Server Management Studio. 43
  • 44. Exercises (2) 3. Typical universities have: faculties, departments, professors, students, courses, etc. Faculties have name and could have several departments. Each department has name, professors and courses. Each professor has name, a set of titles (Ph. D, academician, senior assistant, etc.) and a set of courses. Each course consists of several students. Each student belongs to some faculty and to several of the courses.Your task is to create a data model (E/R diagram) for the typical university in SQL Server using SQL Server Management Studio (SSMS). 4. Create the same data model in MySQL. 44
  • 45. Exercises (3) 5. We should design a multilingual dictionary. We have a set of words in the dictionary. Each word can be in some language and can have synonyms and explanations in the same language and translation words and explanations in several other languages. The synonyms and translation words are sets of words from the dictionary.The explanations are textual descriptions. Design a database schema (a set of tables and relationships) to store the dictionary. 45
  • 46. Exercises (4) 6. Add support in the previous database for storing antonym pairs. Add support for storing part-of-speech information (e.g. verb, noun, adjective, …). Add support for storing hypernym / hyponym chains (e.g. tree  oak, pine, walnut-tree, …). 46
  • 47. FreeTrainings @Telerik Academy  C# Programming @Telerik Academy  csharpfundamentals.telerik.com  Telerik Software Academy  academy.telerik.com  Telerik Academy @ Facebook  facebook.com/TelerikAcademy  Telerik Software Academy Forums  forums.academy.telerik.com