Lecture 7 Data Model Implementation Dan Ames Hydroinformatics Fall 2013 This work was funded by National Science Foundation Grants EPS 1135482 and EPS.

Slides:



Advertisements
Similar presentations
Relational Database Example in Access - Order System Please use speaker notes for additional information!
Advertisements

CC SQL Utilities.
Irwin/McGraw-Hill Copyright © 2000 The McGraw-Hill Companies. All Rights reserved Whitten Bentley DittmanSYSTEMS ANALYSIS AND DESIGN METHODS5th Edition.
Creating Databases and E/R Diagrams with SQL Server Management Studio Svetlin Nakov Telerik Corporation
MS-Access XP Lesson 1. Introduction to MS-Access Database Management System Software (DBMS) Store data in databases Database is a collection of table.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-1 COS 346 Day 20.
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.
Introduction to Structured Query Language (SQL)
Access Lecture 1 Database Overview and Creating Tables Create an Employee Table.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Telerik Software Academy Telerik School Academy Creating E/R Diagrams with SQL Server.
ISOM Comparison of Relational database management systems Arijit Sengupta.
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management.
Working with SQL and PL/SQL/ Session 1 / 1 of 27 SQL Server Architecture.
Copyright ©2014 Pearson Education, Inc. Chapter 6 Physical Design Chapter6.1.
Phil Brewster  One of the first steps – identify the proper data types  Decide how data (in columns) should be stored and used.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
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.
Irwin/McGraw-Hill Copyright © 2000 The McGraw-Hill Companies. All Rights reserved Whitten Bentley DittmanSYSTEMS ANALYSIS AND DESIGN METHODS5th Edition.
1 Chapter 1: Finding Your Way Through a Database Exploring Microsoft Office Access 2010.
ASP.NET Programming with C# and SQL Server First Edition
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
DAY 14: ACCESS CHAPTER 1 Tazin Afrin October 03,
Data-mining & Data As we used Excel that has capability to analyze data to find important information, the data-mining helps us to extract information.
Chapter 15: Using LINQ to Access Data in C# Programs.
1 Working with MS SQL Server Textbook Chapter 14.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
Discovering Computers Fundamentals Fifth Edition Chapter 9 Database Management.
Relational Databases Database Driven Applications Retrieving Data Changing Data Analysing Data What is a DBMS An application that holds the data manages.
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
Module 3: Creating Data Types and Tables. Overview Working with Data Types Working with Tables Generating Column Values Generating Scripts.
1 Chapter 1: Finding Your Way Through a Database Exploring Microsoft Office Access 2007.
DAT602 Database Application Development Lecture 2 Review of Relational Database.
Visual Programing SQL Overview Section 1.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
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
Agenda for Class 2/20/2014 Introduce Microsoft’s SQL Server database management system. Use the lab to discuss how to CREATE, DROP and populate (INSERT)
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
SSMS SQL Server Management System. SQL Server Microsoft SQL Server is a Relational Database Management System (RDBMS) Relational Database Management System.
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
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.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
uses of DB systems DB environment DB structure Codd’s rules current common RDBMs implementations.
Introduction to Database Programming with Python Gary Stewart
Agenda for Today  DATABASE Definition What is DBMS? Types Of Database Most Popular Primary Database  SQL Definition What is SQL Server? Versions Of SQL.
Data Model / Database Implementation Jeffery S. Horsburgh Hydroinformatics Fall 2015 This work was funded by National Science Foundation Grants EPS
CS320 Web and Internet Programming SQL and MySQL
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Data Definition and Data Types
ISC440: Web Programming 2 Server-side Scripting PHP 3
CIS16 Application Programming with Visual Basic
PT2520 Unit 5: Physical Design
CS3220 Web and Internet Programming SQL and MySQL
Chapter 11 Managing Databases with SQL Server 2000
CS3220 Web and Internet Programming SQL and MySQL
CS4540 Special Topics in Web Development SQL and MS SQL
Presentation transcript:

Lecture 7 Data Model Implementation Dan Ames Hydroinformatics Fall 2013 This work was funded by National Science Foundation Grants EPS and EPS

Objectives Understand common database software packages, limitations and capabilities Where are certain databases commonly used? Why and when would you use certain databases? Introduce MS Access Introduce MS SQL Server Management Studio

Who are the main contenders? Commercial software – Sybase Adaptive Server Enterprise – IBM DB2 – Oracle – Microsoft SQL Server – Teradata Free/GPL/Open Source: – MySQL – PostgreSQL

Things to consider when deciding on a DBMS Price Operating System Support Most important features – ACID (Atomicity, Consistency, Isolation, Durability) – Referential Integrity support – Transactions support Scalability and security Availability of support and software Potential longevity

DBMS’s sorted by release date

Operating System Support WindowsMac OS XLinuxBSDUNIX Adaptive Server EnterpriseYes DB2YesNoYesNoYes Microsoft SQL ServerYesNo MySQLYes OracleYes NoYes PostgreSQLYes TeradataYesNoYesNoYes

Let’s Explore more… Go to the wikipedia article “Comparison of relational database management systems” Considering the database you designed in the last homework exercise answer the question… Which two or three DBMSs best meet the needs of my data and potential data management workflow? Why?

SQL Server (Express) Express version free and redistributable, license to commercial version varies between $600 to $10000 Support for Windows only Express version limited to one CPU and single user thread – Limited features, but scales easily to Enterprise version – Comes with all standard SQL tools – support

Oracle Standard Edition Free download for non-profit, non-commercial use Approximately $15000/cpu for commercial use Support for most operating systems Very strong support and service Weak user interface, complex installation and maintenance process

MySQL No limit on # of CPUs, fully featured, support for several OSs $0 without Support, approx. $600-$6000 for subscription-based support Highly scalable, provides support for most types of indexes and storage methods

IBM DB2 Express Free for non-commercial use, $6000 per CPU unlimited users Express version limited to 2 CPUs. Support for Windows, Linux and Unix Strong features set, very good user interface Limited support but can be purchased for additional cost

How would it work in Access?

Basic Database Design Principles Avoid Duplication – Tables, fields, records Enforce Data Integrity – Data are referenced throughout the entire database so that changes made in one table affect other tables Ensure Data Accuracy – Formats (mm-dd-yyyy), pick lists, controlled vocabulary

Main Parts of Database Design Tables Fields Identifying Relationships Enforcing Integrity

Table: inven The ItemNo is the primary key for this table.

Table: invcust The Custid is the primary key for this table. Notice Indexed is Yes with no duplicates.

There is a one to many relationship between the order header table (orderz) and the order line item table (ordline). This means for every order there can be multiple line items, but for each line item there is only one order. I can find out the line items by going into the ordline table and retrieving all records that match the order number for a given order. Because there are multiple line items with the same order number, I have to use the combination or order number and item number to make a unique primary key. Tables: orderz & ordline Ordno is the primary key. Ordno and Itemno are the primary keys.

The primary key is Slsrep. Tables: Salesrep & Department The primary key is Dept.

Relationships

Query: Inven & Department SELECT Inven.ItemNo, Inven.ItemName, Inven.Dept, Department.Deptname, Department.Manager FROM Department INNER JOIN Inven ON Department.Dept = Inven.Dept; SELECT ItemNo, ItemName, Inven.Dept, Deptname, Manager FROM Inven, Department WHERE Department.Dept = Inven.Dept; Access SQL code. My SQL code. From inven. From department.

Queries: Orderz & Invcust SELECT Orderz.Ordno, Orderz.Custid, Invcust.Custname, Orderz.Ordate FROM Invcust INNER JOIN Orderz ON Invcust.Custid = Orderz.Custid; SELECT Ordno, Orderz.Custid, Custname, Ordate FROM Orderz, InvCust WHERE Invcust.Custid = Orderz.Custid; Access SQL code My SQL code Custname from Invcust table - the rest from Orderz table.

SELECT Orderz.Ordno, Orderz.Custid, Orderz.Ordate, Ordline.Itemno, Ordline.Numord FROM Orderz INNER JOIN Ordline ON Orderz.Ordno = Ordline.Ordno; SELECT Orderz.Ordno, Custid, Ordate, Itemno, Numord FROM Orderz, Ordline WHERE Orderz.Ordno = Ordline.Ordno; Query: Orderz & Ordline Access SQL code My SQL code From Orderz From ordline

SELECT Orderz.Ordno, Ordline.Itemno, Inven.ItemName, Ordline.Numord FROM Inven INNER JOIN (Orderz INNER JOIN Ordline ON Orderz.Ordno = Ordline.Ordno) ON Inven.ItemNo = Ordline.Itemno; Query: Orderz, Ordline, Inven SELECT Orderz.Ordno, Ordline.Itemno, Inven.ItemName, Ordline.Numord FROM Orderz, Ordline, Inven WHERE Orderz.Ordno = Ordline.Ordno AND Inven.ItemNo = Ordline.Itemno; Access SQL My SQL

Query on 4 tables SELECT Orderz.Ordno, Orderz.Custid, Invcust.Custname, Orderz.Ordate, Ordline.Itemno, Inven.ItemName, Ordline.Numord FROM (Invcust INNER JOIN Orderz ON Invcust.Custid = Orderz.Custid) INNER JOIN (Inven INNER JOIN Ordline ON Inven.ItemNo = Ordline.Itemno) ON Orderz.Ordno = Ordline.Ordno; SELECT Orderz.Ordno, Orderz.Custid, Custname, Ordate, Ordline.Itemno, ItemName, Numord FROM Invcust, Orderz, Ordline, Inven WHERE Invcust.Custid = Orderz.Custid AND Inven.ItemNo = Ordline.Itemno AND Orderz.Ordno = Ordline.Ordno; Access SQL My SQL

The Access Window New Perspectives on Microsoft Access

Databases and Relationships New Perspectives on Microsoft Access

Entering Records New Perspectives on Microsoft Access

How would it work in SQL Server Management Studio?

MS SQL Server 2008MS SQL Server 2008 Overview SQL Server Slides adapted from

What is Microsoft SQL Server?What is Microsoft SQL Server? MS SQL Server is a Relational Database Management System (RDBMS) from Microsoft 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 The most recent version is SQL Server 2008 Works only on Windows systems Works only on Windows systems A free distribution exists (SQL Server Express) A free distribution exists (SQL Server Express) –

Connecting to SQL ServerConnecting to SQL Server Connecting to SQL Server requires 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 Types of authentication in SQL Server – Windows (by using a Windows user credentials) – Mixed (both Windows and SQL Server) 33

SQL Server Management Studio (SSMS)SQL Server Management Studio (SSMS) SQL Server Management Studio (SSMS) is a powerful graphical DB management tool 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 34

SQL Server Management Studio – Screenshot 35

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

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

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)

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

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

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

Database Modeling with SQL Server Management Studio Creating a 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

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 44

Creating a New Database In Object Explorer we go to the "Databases" and choose "New Database…" from the context menu 45

Creating a New Database (2) In the "New Database" window enter the name of the new database and click [OK] 46

Database Modeling with SQL Server Management Studio Creating E/R Diagrams 47

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 48

Database Modeling with SQL Server Management Studio Creating Tables

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

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

Creating Tables (3) Defining a primary key 52 Right click on the column start and select "Set Primary Key"

Creating Tables (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 53

Creating Tables (5) Setting an identity through the "Column Properties" window 54

Creating Tables (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] 55 Tablen ame

Creating Tables (7) 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 56

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 58

Self-Relationships Self-relationship can be created by dragging a foreign key onto the same table 59

Database Modeling with SQL Server Management Studio 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 61

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 62

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 63

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: 64