Database Modeling. Creating E/R Diagrams with SQL Server Management Studio and MySQL Workbench. Telerik School Academy

Similar documents
Using SQL Server Management Studio

Creating Database Tables in Microsoft SQL Server

How To Create A Table In Sql (Ahem)

Introduction This document s purpose is to define Microsoft SQL server database design standards.

Table and field properties Tables and fields also have properties that you can set to control their characteristics or behavior.

Ken Goldberg Database Lab Notes. There are three types of relationships: One-to-One (1:1) One-to-Many (1:N) Many-to-Many (M:N).

Web Testing. Main Concepts of Web Testing. Software Quality Assurance Telerik Software Academy

Once the schema has been designed, it can be implemented in the RDBMS.

DbSchema Tutorial with Introduction in SQL Databases

SQL Server An Overview

WINDOWS AZURE SQL DATA SYNC

Toad Data Modeler - Features Matrix

Ontrack PowerControls V8.1 for SQL ReadMe

CSCE 156H/RAIK 184H Assignment 4 - Project Phase III Database Design

Create a Database Driven Application

Topic: Relationships in ER Diagram and Relationships in MS Access

The Entity-Relationship Model

MS ACCESS DATABASE DATA TYPES

A table is a collection of related data entries and it consists of columns and rows.

Fundamentals of Database Design

A Short Tutorial on Using Visio 2010 for Entity-Relationship Diagrams

Ontrack PowerControls User Guide Version 8.0

Web Service Testing. SOAP-based Web Services. Software Quality Assurance Telerik Software Academy

ODBC Client Driver Help Kepware, Inc.

Power*Architect User Guide. SQL Power Group Inc. [

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

Getting Started with Telerik Data Access. Contents

Deployment Guide. Cartagena as. Cartagena ERP Integration 3.0 for Microsoft Dynamics CRM. Knut Eivind Handeland

Database Setup. Coding, Understanding, & Executing the SQL Database Creation Script

Doing database design with MySQL

Stellar Phoenix. SQL Database Repair 6.0. Installation Guide

B.1 Database Design and Definition

From Data Modeling to Data Dictionary Written Date : January 20, 2014

Customer Bank Account Management System Technical Specification Document

The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

HTML5. Turn this page to see Quick Guide of CTTC

SQL Server Table Design - Best Practices

Database Design and Normalization

Database Systems. S. Adams. Dilbert. Available: Hans-Petter Halvorsen, M.Sc.

Relational Databases. Christopher Simpkins

types, but key declarations and constraints Similar CREATE X commands for other schema ëdrop X name" deletes the created element of beer VARCHARè20è,

Table of contents. Reverse-engineers a database to Grails domain classes.

CSCI110 Exercise 4: Database - MySQL

Skills for Employment Investment Project (SEIP)

USER GUIDE Appointment Manager

Database Migration : An In Depth look!!

Bitrix Site Manager 4.1. User Guide

A Tool for Generating Relational Database Schema from EER Diagram

Database Normalization And Design Techniques

Talend for Data Integration guide

Exploring Microsoft Office Access Chapter 2: Relational Databases and Multi-Table Queries

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

Lecture 6. SQL, Logical DB Design

DbSchema Tutorial with Introduction in MongoDB

Welcome to the Data Analytics Toolkit PowerPoint presentation on EHR architecture and meaningful use.

Facebook Twitter YouTube Google Plus Website

INFORMATION BROCHURE Certificate Course in Web Design Using PHP/MySQL

Linas Virbalas Continuent, Inc.

Table Of Contents. iii

Access Part 2 - Design

AUTHENTICATION... 2 Step 1:Set up your LDAP server... 2 Step 2: Set up your username... 4 WRITEBACK REPORT... 8 Step 1: Table structures...

Tutorial on Relational Database Design

How Strings are Stored. Searching Text. Setting. ANSI_PADDING Setting

Rapid Application Development. and Application Generation Tools. Walter Knesel

Managing Objects with Data Dictionary Views. Copyright 2006, Oracle. All rights reserved.

Oracle Database 10g Express

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC

ATTACHMENT 6 SQL Server 2012 Programming Standards

Umbrello UML Modeller Handbook

Structured Query Language. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

The Relational Data Model: Structure

1. To start Installation: To install the reporting tool, copy the entire contents of the zip file to a directory of your choice. Run the exe.

Porting from Oracle to PostgreSQL

4 Simple Database Features

Data Generator for SQL Server User's Manual EMS Database Management Solutions

IBM DB2 XML support. How to Configure the IBM DB2 Support in oxygen

LAB 1: Getting started with WebMatrix. Introduction. Creating a new database. M1G505190: Introduction to Database Development

Developing Physical Solutions for InfoSphere Master Data Management Server Advanced Edition v11. MDM Workbench Development Tutorial

FmPro Migrator - FileMaker to SQL Server

COSC 6397 Big Data Analytics. 2 nd homework assignment Pig and Hive. Edgar Gabriel Spring 2015

SAP Business Objects Business Intelligence platform Document Version: 4.1 Support Package Data Federation Administration Tool Guide

Databases in Engineering / Lab-1 (MS-Access/SQL)

[MS-WSSDM]: Windows SharePoint Services: Content Database Data Migration Communications Protocol Specification

Form And List. SuperUsers. Configuring Moderation & Feedback Management Setti. Troubleshooting: Feedback Doesn't Send

Black Hat Briefings USA 2004 Cameron Hotchkies

Software Engineering I CS524 Professor Dr. Liang Sheldon X. Liang

Address Phone & Fax Internet

Talend Open Studio for MDM. Getting Started Guide 6.0.0

Working with DB2 UDB objects

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

Abstract. For notes detailing the changes in each release, see the MySQL for Excel Release Notes. For legal information, see the Legal Notices.

J j enterpririse. Oracle Application Express 3. Develop Native Oracle database-centric web applications quickly and easily with Oracle APEX

How to Configure the Workflow Service and Design the Workflow Process Templates

IRF2000 IWL3000 SRC1000 Application Note - Apps with OSGi - Condition Monitoring with WWH push

Transcription:

Database Modeling Creating E/R Diagrams with SQL Server Management Studio and MySQL Workbench Telerik School Academy Telerik Software Academy http://schoolacademy.telerik.com

Table of Contents 1. Data Modeling 2. Data Types in SQL Server 3. Creating Databases in SQL Server Creating Tables Defining a Primary Key and Identity Columns Creating Relationships between the Tables One-to-many, Many-to-many, One-to-one 4. Naming Conventions 5. Data Modeling in MySQL Workbench 2

1. Data Modeling 2. Data Types in SQL Server 3. Creating Databases in SQL Server Creating Tables Defining a Primary Key and Identity Columns Creating Relationships between the Tables One-to-many, Many-to-many, One-to-one 4. Naming Conventions 5. Data Modeling in MySQL Workbench 3

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: 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. Entities: Student, Course, Town 5

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: 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. Students have the following characteristics: Name, faculty number, photo, date of enlistment and a list of courses they visit 7

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: 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. "Students are trained in courses" many-tomany relationship "Courses are held in towns" many-to-one (or many-to-many) relationship 9

1. Data Modeling 2. Data Types in SQL Server 3. Creating Databases in SQL Server Creating Tables Defining a Primary Key and Identity Columns Creating Relationships between the Tables One-to-many, Many-to-many, One-to-one 4. Naming Conventions 5. Data Modeling in MySQL Workbench 10

Data Types 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

Binary data Data Types in SQL Server (2) 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

Other types Data Types in SQL Server (3) timestamp automatically generated number whenever a change is made to the data row uniqueidentifier GUID identifier xml data in XML format 13

Data Types 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

1. Data Modeling 2. Data Types in SQL Server 3. Creating Databases in SQL Server Creating Tables Defining a Primary Key and Identity Columns Creating Relationships between the Tables One-to-many, Many-to-many, One-to-one 4. Naming Conventions 5. Data Modeling in MySQL Workbench 15

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

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 20

1. Data Modeling 2. Data Types in SQL Server 3. Creating Databases in SQL Server Creating Tables Defining a Primary Key and Identity Columns Creating Relationships between the Tables One-to-many, Many-to-many, One-to-one 4. Naming Conventions 5. Data Modeling in MySQL Workbench 21

Creating Tables If the database doesn't show immediately in Object Explorer perform "Refresh" [F5] Creating new table: 22

Creating Tables (2) Enter table name and define the table columns (name and type): Enter the name of the column here Choose the data type of the column here Choose whether NULLs are allowed 23

Creating Tables (3) 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] Table name 24

Creating Tables (4) When closing the window for the table, SSMS asks whether to save the table You can do it manually by choosing Save Table from the File menu or by pressing Ctrl + S 25

1. Data Modeling 2. Data Types in SQL Server 3. Creating Databases in SQL Server Creating Tables Defining a Primary Key Creating Relationships between the Tables One-to-many, Many-to-many, One-to-one 4. Naming Conventions 5. Data Modeling in MySQL Workbench 26

Defining a primary key Right click on the column start and select "Set Primary Key" Defining Primary Key 27

Defining an identity columns Defining Primary Key (1) 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 28

Defining Primary Key (2) Setting an identity through the "Column Properties" window 29

1. Data Modeling 2. Data Types in SQL Server 3. Creating Databases in SQL Server Creating Tables Defining a Primary Key Creating Relationships One-to-many, Many-to-many, One-to-one 4. Naming Conventions 5. Data Modeling in MySQL Workbench 30

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

1. Data Modeling 2. Data Types in SQL Server 3. Creating Databases in SQL Server Creating Tables Defining a Primary Key Creating Relationships One-to-many, Many-to-many, One-to-one 4. Naming Conventions 5. Data Modeling in MySQL Workbench 33

Tables Naming Conventions 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

Primary key Naming Conventions (2) 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

Unique key constraints names Naming Conventions (4) "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

1. Data Modeling 2. Data Types in SQL Server 3. Creating Databases in SQL Server Creating Tables Defining a Primary Key Creating Relationships One-to-many, Many-to-many, One-to-one 4. Naming Conventions 5. Data Modeling in MySQL Workbench 39

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

форум програмиране, форум уеб дизайн Database Modeling курсове и уроци по програмиране, уеб дизайн безплатно курсове и уроци по програмиране Телерик академия уроци по програмиране и уеб дизайн за ученици програмиране за деца безплатни курсове и уроци безплатен SEO курс - оптимизация за търсачки курсове и уроци по програмиране, книги безплатно от Наков уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop free C# book, безплатна книга C#, книга Java, книга C# безплатен курс "Качествен програмен код" безплатен курс "Разработка на софтуер в cloud среда" BG Coder - онлайн състезателна система - online judge ASP.NET курс - уеб програмиране, бази данни, C#,.NET, ASP.NET ASP.NET MVC курс HTML, SQL, C#,.NET, ASP.NET MVC алго академия състезателно програмиране, състезания курс мобилни приложения с iphone, Android, WP7, PhoneGap Дончо Минков - сайт за програмиране Николай Костов - блог за програмиране C# курс, програмиране, безплатно 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

Free Trainings @ 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