Creating Databases and E/R Diagrams with SQL Server Management Studio Svetlin Nakov Telerik Corporation www.telerik.com.

Slides:



Advertisements
Similar presentations
BetterInvestings Portfolio Manager Improving Mutual Fund Decisions Created by: QUANT IX SOFTWARE, Inc. Revised: November, 2005.
Advertisements

Advanced SQL Topics Edward Wu.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizards Guide to PHP by David Lash.
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
McGraw-Hill/Irwin Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. Extended Learning Module D (Office 2007 Version) Decision Analysis.
BASIC SKILLS AND TOOLS USING ACCESS
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
Structured Query Language (SQL)
Microsoft Access 2007 Advanced Level. © Cheltenham Courseware Pty. Ltd. Slide No 2 Forms Customisation.
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
Relational data objects 1 Lecture 6. Relational data objects 2 Answer to last lectures activity.
1 Using SPSS: Introduction Department of Operations Weatherhead School of Management.
ETS4 - What's new? - How to start? - Any questions?
© Telcordia Technologies 2004 – All Rights Reserved AETG Web Service Advanced Features AETG is a service mark of Telcordia Technologies. Telcordia Technologies.
Campaign Overview Mailers Mailing Lists
Chapter 7 Working with Databases and MySQL
9 Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Creating Tables, Setting Constraints, and Datatypes What is a constraint and why do we use it? What is a datatype? What does CHAR mean? Page 97 in Course.
R ELATIONAL M ODEL TO SQL Data Model. 22 C ONCEPTUAL D ESIGN : ER TO R ELATIONAL TO SQL How to represent Entity sets, Relationship sets, Attributes, Key.
Microsoft Office Illustrated Fundamentals Unit K: Working with Data.
Microsoft Access.
CC SQL Utilities.
Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to.
1 tRelational/DPS Overview. 2 ADABAS Data Transfer: business needs and issues tRelational & DPS Overview Summary Questions? Demo Agenda.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Ticket Information Application.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
4 Oracle Data Integrator First Project – Simple Transformations: One source, one target 3-1.
Services Course Windows Live SkyDrive Participant Guide.
MS-Access XP Lesson 1. Introduction to MS-Access Database Management System Software (DBMS) Store data in databases Database is a collection of table.
Chapter 2 Entity-Relationship Data Modeling: Tools and Techniques
Types of selection structures
Chapter 12: Designing Databases
Essential Cell Biology
Database Chapters.
RefWorks: The Basics October 12, What is RefWorks? A personal bibliographic software manager –Manages citations –Creates bibliogaphies Accessible.
© Paradigm Publishing, Inc Access 2010 Level 2 Unit 2Advanced Reports, Access Tools, and Customizing Access Chapter 8Integrating Access Data.
Import Tracking and Landed Cost Processing An Enhancement For AS/400 DMAS from  Copyright I/O International, 2001, 2005, 2008, 2012 Skip Intro Version.
1.step PMIT start + initial project data input Concept Concept.
Know About E-CTLT Teachers Panel and working area.
Windfall Web Throughout this slide show there will be hyperlinks (highlighted in blue). Follow the hyperlinks to navigate to the specified Topic or Figure.
Microsoft SQL Server 2008 From the Program menu choose: Microsoft SQL Server 2008 R2  SQL Server Management Studio. You may see a window indicating the.
Module 4: Creating Data Types and Tables. Overview Creating Data Types Creating Tables Generating Column Values Generating Scripts.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Data Modelling. EAR model This modelling language allows a very small vocabulary: Just as English has nouns, verbs, adjectives, pronouns.., EAR models.
Telerik Software Academy Telerik School Academy Creating E/R Diagrams with SQL Server.
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management.
Copyright ©2014 Pearson Education, Inc. Chapter 6 Physical Design Chapter6.1.
Overview What is SQL Server? Creating databases Administration Security Backup.
Overview of SQL Server Alka Arora.
Creating E/R Diagrams with SQL Server Management Studio and MySQL Workbench Svetlin Nakov Telerik Software Academy Manager Technical.
Databases in Visual Studio. Database in VisualStudio An MS SQL database are built in Visual studio The Name can be something like ”(localdb)\Projects”
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
DAT602 Database Application Development Lecture 2 Review of Relational Database.
Session 11 Creating Tables and Using Data Types. RDBMS and Data Management/Session 11/2 of 40 Session Objectives Define the data types and list the categories.
GLOBEX INFOTEK Copyright © 2013 Dr. Emelda Ntinglet-DavisSYSTEMS ANALYSIS AND DESIGN METHODSINTRODUCTORY SESSION EFFECTIVE DATABASE DESIGN for BEGINNERS.
Database Basics BCIS 3680 Enterprise Programming.
Data Modeling Creating E/R Diagrams SoftUni Team Technical Trainers Software University
SSMS SQL Server Management System. SQL Server Microsoft SQL Server is a Relational Database Management System (RDBMS) Relational Database Management System.
Creating E/R Diagrams with SQL Server Management Studio, Writing SQL Queries D0ncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer.
Introduction to SQL Server  Working with MS SQL Server and SQL Server Management Studio.
Lecture 7 Data Model Implementation Dan Ames Hydroinformatics Fall 2013 This work was funded by National Science Foundation Grants EPS and EPS.
Databases and SQL Designing a database with tables and primary keys
Database Design and Rules
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Module 2: Creating Data Types and Tables
Data Definition and Data Types
CIS16 Application Programming with Visual Basic
PT2520 Unit 5: Physical Design
Chapter 2: Creating And Modifying Database Tables
Chapter 11 Managing Databases with SQL Server 2000
Presentation transcript:

Creating Databases and E/R Diagrams with SQL Server Management Studio Svetlin Nakov Telerik Corporation

1. Introduction to SQL Server 2. Data Modeling – Principles 3. Data Types in SQL Server 4. Creating Databases in SQL Server 5. Creating Tables 6. Defining a Primary Key and Identity Columns 7. Creating Relationships between the Tables  One-to-many, Many-to-many, One-to-one 8. Naming conventions 2

MS SQL Server 2008MS SQL Server 2008 Overview

What is Microsoft SQL Server?What is Microsoft SQL Server?  MS SQL Server is a Relational Database Management System (RDBMS) from Microsoft  The main language supported in SQL Server is Transact SQL (T-SQL), an extension of SQL  Powerful, trustworthy, easy-to-use DB server  The most recent version is SQL Server 2008  Works only on Windows systems  A free distribution exists (SQL Server Express)  4

Connecting to SQL ServerConnecting to SQL Server  Connecting to SQL Server requires  The name of the server machine / IP address  The name of the server instance  The name of the database  Username / password (if using SQL Server authentication)  Types of authentication in SQL Server  Windows (by using a Windows user credentials)  Mixed (both Windows and SQL Server) 5

SQL Server Management Studio (SSMS)  SQL Server Management Studio (SSMS) is a powerful graphical DB management tool  Administrate databases (create, modify, backup / restore DB)  Create and modify E/R diagrams  View / modify table data and other DB objects  Execute SQL queries  Free and easy to use tool  Works with all SQL Server versions 6

SQL Server Management Studio – Screenshot 7

SQL Server DatabasesSQL Server Databases 8 System Databases User Databases model tempdb msdb distribution pubsNorthwind… master

SQL Server DatabasesSQL Server Databases  Each SQL Server database consists of two files: .mdf file  Contains the core data in the database  Schema, tables data, and other database objects .ldf file  Transaction log – keeps track of transactions  You need both these files to use the database  You can move a database by SQL scripting, backup / restore, or copy the.mdf /.ldf files 9

SQL Server Management Studio Live DemoLive Demo

Fundamental Concepts

 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 12

 Entity tables represent objects from the real world  Most often they are nouns in the specification  For example:  Entities: Student, Course, Town 13 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.

 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) 14

 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 15 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.

 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) 16

 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 17 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.

 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) 19

 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 to , a precision of 1/300 sec.  smalldatetime – date and time (1-minute precision) 20

 Other types  timestamp – automatically generated number whenever a change is made to the data row  uniqueidentifier – GUID identifier  xml – data in XML format 21

 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 22

Creating a Database

 When starting SSMS a window pops up  Usually it is enough to just click the "Connect" button without changing anything 24

 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 25

 In Object Explorer we go to the "Databases" and choose "New Database…" from the context menu 26

 In the "New Database" window enter the name of the new database and click [OK] 27

Creating E/R Diagrams

 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 29

Creating Tables

 If the database doesn't show immediately in Object Explorer perform "Refresh" [F 5 ]  Creating new table: 31

 Enter table name and define the table columns (name and type): 32 Enter the name of the column here Choose the data type of the column here Choose whether NULLs are allowed

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

 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 34

 Setting an identity through the "Column Properties" window 35

 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] 36 Table name

 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 37

Creating Relationships between Tables

 To create one-to-many relationship drag the foreign key column onto the other table  Drag from the child table to the parent table 39

 Self-relationship can be created by dragging a foreign key onto the same table 40

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 42

 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 43

 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 44

 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: 45

Live Demo

Questions?