cis 338: vb.net & databases dr. ralph d. westfall may, 2011

23
CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Upload: clara-atkins

Post on 13-Dec-2015

219 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

CIS 338: VB.NET & Databases

Dr. Ralph D. WestfallMay, 2011

Page 2: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

What Is a Database?

shared collection of logically related datadesigned to meet needs of multiple users

McFadden & Hofer, 1994

Page 3: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Database Advantages

less redundant than separate application filesconsistency of data e.g., field lengthsintegration of datadata sharingeasier application developmentscalability

Page 4: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Database Advantages - 2

better security, privacy, integrity controlsstandardization e.g., field namesdata accessibility and responsivenessdata independencereduced program maintenance e.g., centralized validation

Page 5: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Database Advantages - 3

more efficient technology than most "third generation" application programs powerful code to access items, search

and sort data storage optimization (disk,

memory) efficient updating: add, change, delete

Page 6: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Database - Disadvantages

uses more resources than file-based systems hardware, software

requires specialized personnel potential data access conflicts operations vs. data mining

potential organizational conflictsincompatibilities between database systems

Page 7: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Database Design

determine functional requirementsidentify data required for applicationsorganize the data tables (usually normalized) relationships between tables

identify business rules (middle tier)design queries and applications

Page 8: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Key Fields

each row in a table is uniquely identified by one or more key field(s)ID# Name City322 Karim Pomona

Dr# Patient# Appointment397 0246875 10/24/00 2 PM 'key field(s) underlined

Page 9: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Rules for Tables in a Database

all items in each table should relate to one main topic or subject, on a one-to-one basis employees: Id#, SS#, Name, Address, Pay paychecks: CheckID#, ID#, Date, Amount

tables should be "normalized" (2NF or more) no repeated information no fields that may be intentionally empty no fields with data that can be calculated

(derived) from other fields Notes

Page 10: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Normalization

splitting tables to avoid problems avoid duplicated data and empty cells avoid problems: add, change or delete

dataSID Name GWE Class Quarter Grade

322 Ana No C101 F99 pass

322 Ana No C234 S00 A use 2 tables instead

1-SID, Name, GWE; 2-SID, Class, Quarter, Grade

Page 11: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Normalization - 2

library has borrowers, books, circulation put circulation in borrowers file?

repeating patron data for every checked out book

Borrower#, Name, Address, Book# or repeating (often empty) columnsBorrower#, Name, Address, Bk#1, Bk#2, etc.

normalize: separate borrowers, circulationBook #, Title, Author, Year, etc.

Patron#, Name, Address, etc.

Patron#, Book#, Due Date

Page 12: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Specialized Normalized Tables

"parent-child tables" boss is an employee, but so are people

working for her all have the same attribute fields, including

a field that has ID of each one's boss

"lookup table" zip, city, state

zip code "determines" city and state those can come from a table keyed by zip

code Cerritos mail used to be addressed to Artesia

Page 13: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Denormalization

sometimes more efficient to not completely normalize all tables less normalization can increase

efficiency and possibly reduce number of tables e.g., 1 customer table with fields for 2

voice phone numbers only need to update 1 table don't need to do a join to get all phone

#s

Page 14: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Denormalization - 2

"do not store data in a table if it can be calculated from other data" (in 3NF) e.g., total field (in a separate table) but with a total field don't need to total a

large # of records every time need a total but do need extra code to update totals

when records are added, changed or deleted (like a "getter" in OO code)

Page 15: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Creating a Database or Table

using SQL commands in VB.NET using VB.NET Server Explorer using "3rd party" programs or "shells" similar to Server Explorer approach or

more sophisticated SQL Server Management Studio, for

example

Page 16: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Creating a Database in Access

Access 2003 new database options Design View

user needs to type in Field Name, select Data Type, input Field Size and other properties

wizard that provides common templates entering data manually

uses default settings (like a spreadsheet)

Page 17: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Create Database in Access - 2

could use External Data>Import>More to pull in data from a file, other databases, spreadsheets, etc. could go into a new table, or be added

to an existing table need to set field properties when

bringing in data to a new table e.g., Field Name, Data Type, etc.

Page 18: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

SQL Server and Express

Microsoft's SQL Server is designed to handle very large scale applications more security, transaction logging ,

stored procedures, very many users, etc.

SQL Server 2008 is the software that runs SQL Server database the "engine" in Access 2003 is Jet 4.0 but Access can read/write SS 2008

Page 19: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Create SQL Server DB with Server Explorer

to create SQL Server Express Edition database (optional for Project 2) install SQL Server Express 2008 use Start>Control Panel>System>

Computer Name and then copy the name stop at the dot if it has a domain name

View>Server Explorer in .NET

Page 20: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

SSExpress with Server Explorer

right-click Data Connections>Create New SQL Server Database>paste in the (local)\SQLEXPRESSbe sure Use Windows Authentication is selected>type something in New database name>OK

Page 21: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

SSExpress with Server Explorer - 2

expand the Data Connections iconright-click Tables>Add New Table type in Column Names type/select Type, Length, etc. File>Close or right click tab>Close

after enter last field File>Save Table1 and replace name

in Choose Name input box

Page 22: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

File Location Issues

default location of new file (my machine) c:\Program Files\Microsoft SQL Server\

MSSQL10.SQLEXPRESS\MSSQL\DATA could right-click database name>Publish

to provider to relocate

could also use SQL Server Management Studio to manipulate databases created within Visual Studio

Page 23: CIS 338: VB.NET & Databases Dr. Ralph D. Westfall May, 2011

Convert Access to SQL Server

in Access 2007 Database Tools>Move Data>SQL Server

icon>Create new database>Next type in (local)\SQLEXPRESS, check Use

Trusted Connection>[type new file name]>Next>[select tables]>Next>Next> No application changes>Next>Finish

goes into default location (previous slide)