Upload
quon-bell
View
80
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Database, SQL, & ADO.Net. Chapter 19. Quote for Today. Get your facts first, and then you can distort them as much as you please. Mark Twain It is a capital mistake to theorize before one has data. Arthur Conan Doyle. Database Systems. An integrated collection of related data - PowerPoint PPT Presentation
Citation preview
04/19/23 VBAN09 1
Database, SQL, & ADO.Net
Chapter 19
04/19/23 VBAN09 2
Quote for TodayGet your facts first, and then you can
distort them as much as you please.
Mark TwainIt is a capital mistake to theorize
before one has data.Arthur Conan Doyle
04/19/23 VBAN09 3
Database SystemsAn integrated collection of related dataProvide file-processing capabilitiesOrganize data to enhance retrieval of data in meaningful ways
Query a question a request for information based on specific criteria
SQL - Structured Query Language (pronounced sequel)
used universally to query databases
04/19/23 VBAN09 4
Hierarchy of a DBMSDBMS (DataBase Management System)
made up of one or more databases
Databases
Tables/Queries/Forms/Reports (also known as files in other databases)
Records
Fields
Characters
04/19/23 VBAN09 5
Relational Database Systems
Microsoft SQL ServerOracle ™Sybase ™DB2 ™Informix ™MySQL™Microsoft Access
04/19/23 VBAN09 6
Database System Advantages
Redundancy can be reducedInconsistencies can be avoidedData can be sharedStandards can be enforcedSecurity restrictions can be appliedIntegrity can be maintainedConflicting requirements can be balanced
04/19/23 VBAN09 7
Database Management System
(DBMS) - where the actual manipulation of the database occurs.
This separation from the user interface simplifies the design process.
EndUser
ApplicationSoftware
Databasemanagement
system
Actualdatabase
Data seen interms of the application
Data seen interms of a database model
Data seen in itsactual organization
Conceptual layers of a database
“UserInterface”
04/19/23 VBAN09 8
Data Independence
Applications are separate from how the data is physically stored or accessed.Makes it easy to have different views of the same data by different applications.Data Dependence is an application where the storage
structure and accessing strategy cannot be changed without affecting the application significantly.
04/19/23 VBAN09 9
Database Languages
Users interact with data in databases through the use of database languages.Applications can use higher-level languages to interface with databases. VB, C, C++, Java, COBOL, PL/I or Pascal Queries of the database are made
through the use of a query language Structured Query Language (SQL)
04/19/23 VBAN09 10
Host Languages
Query languages that make it easy to express requests in the context of a particular application.Each host language ordinarily includes a Database Sublanguage (DSL)
04/19/23 VBAN09 11
Database Sublanguage (DSL)
Concerned with the specifics of database objects and operations combination of 2 languages
Data Definition Language (DDL) - facilities for defining database objects
Data Manipulation Language (DML) - provides features for specifying the processing to be performed on database objects.
SQL includes both DDL and DML
04/19/23 VBAN09 12
Distributed Database
A database that is spread throughout the computer systems of a network. Provides the control and economics of
local processing with the advantages of information accessibility over a geographically dispersed organization. Each data item is stored at the location in
which it is most frequently used The item remains accessible to other
network users.
04/19/23 VBAN09 13
DD - Disadvantages
Costly to ImplementCostly to OperateVulnerable to security violations
04/19/23 VBAN09 14
Distributed Databases - Advantage 1
Without a DBMS, the application software would have to know where all of the pieces of the database were stored.
With a DBMS, the application software can be written as if the database were all on one machine.
Pensacola
database
Machine 1
Conceptof one
database Ft. Walton
database
Machine 2
Milton
database
Machine 3
04/19/23 VBAN09 15
DD - Advantage 2 Separating the application software from the
DBMS helps control access to the database. By providing different interfaces for different
users, access is controlled.
PayrollUser
ApplicationSoftware
InventoryUser
User Interfaces
Ex. Payroll and Inventory personnel require different parts of the database. By providing each group a different user interface, access is restricted to other areas of the database.
04/19/23 VBAN09 16
Old vs. New
CustomerRecords
PayrollRecords
EmployeeRecords
InventoryRecords
CustomerServiceDept.
PayrollDept.
PersonnelDept.
PurchasingDept.
Database-oriented Information System
ConsolidatedDatabase
CustomerServiceDept.
Payroll Dept. Personnel Dept.
PurchasingDept.
File-oriented Information SystemOld
NEW
04/19/23 VBAN09 17
DD - Advantage 3The organization of the database can be changed without changing the application software.Supports the concept of data independence.Only the schema used by the central system and the subschemas to those users involved in the change are impacted.
04/19/23 VBAN09 18
DD - Advantage 4Software at the application level is written from a simplified, conceptual view of the database rather than the actual, complex, detailed view of the database.VB frequently provides the user interfaces to the database. The database can be written in several different database languages.
04/19/23 VBAN09 19
Relational Database ModelLogical representation of data that allows relationships among data to be considered without concern for the physical structure of the data.Popular Database Models Hierarchical Database Network Database Relational Database - most popular
04/19/23 VBAN09 20
Relational DatabaseA logical representation of the data that allows the relationships between the data to be considered without concerning oneself with the physical implementation of the data structures.
Codd, 1988Composed of tables
04/19/23 VBAN09 21
TablesRelated data divided up into fields (columns) and records (rows)
Should contain a Primary Key An identifier that is unique to each
record Examples include SSN, Vehicle ID #’s,
Employee ID #’s, Course #’s, Reference #’s. Usually are associated with an ordering
Ascending or Descending
04/19/23 VBAN09 22
Example
CourseNo RefNo Instructor CampusCGS1100 15689 McManus DLCGS1100 15690 McManus FWBCGS1100 15692 McManus FWBCGS1100 15693 McManus FWBCGS1570 15706 McManus FWBCGS1570 15707 McManus DLCIS1000 15735 McManus DLCOP2011 17055 McManus NicevilleCOP2010 17056 McManus Niceville
Records
Fields
Primary Key
04/19/23 VBAN09 23
Projections & JoinsProjection Selecting a subset of fields from a set
of records Filters and Queries
Join Combining selected fields from multiple
tables. Queries
Both are accomplished through SQL.
04/19/23 VBAN09 24
Advantages over Hierarchical & Network Schemes1. Tabular representation is easier for
users to understand and easier to implement in the physical database system.
2. Easy to convert other database structures into a relational scheme.
3. Projection and join operations are easy to implement and make the creation of new tables easy.
04/19/23 VBAN09 25
Advantages cont.4. Searches are generally faster than
when using schemes that use pointers.5. Relational structures are easier to
modify.Advantage when flexibility is an issue.
6. Database clarity and visibility.Tabular format is easier for the user to search than when using more complex structures.
04/19/23 VBAN09 26
Primary KeysUniquely identifies each record in the table. Rule of Entity Integrity
Every record must have a value in the primary key field
The value must be unique Duplicates -- not allowed
04/19/23 VBAN09 27
Foreign KeysA field in a table for which every entry has a unique value in another table and where the field in the other table is the primary key for that table. Rule of Referential Integrity
every value in a foreign key field must appear in another table’s primary key field
Provide the means of joining multiple tables
04/19/23 VBAN09 28
SQL Query KeywordsSQL Keyword Description
SELECT Selects (retrieves fields from one or more tables
FROMSpecifies tables from which to get fields or delete records. Required in every SELECT and DELETE statement.
WHERE Specifies criteria that determines the rows to be retrieved
INNER JOINJoins records from multiple tables to produce a single set of records
GROUP BY Specifies criteria for grouping records
ORDER BY Specifies criteria for ordering records
INSERT Inserts data into a specified table
UPDATE Updates data in a specified table
DELETE Deletes data from a specified table
04/19/23 VBAN09 29
SQL CommandsSELECT Chooses information from one or more
tables in a database.
SELECT * FROM TableName
The * indicates that all fields from TableName should be selected
SELECT Au_ID, LastName FROM Authors
04/19/23 VBAN09 30
SQL CommandsWHERE Clause Provides the selection criteria
Records must match the criteria in order to be selected
SELECT * FROM Authors WHERE [Year Born] >= 1950SELECT * FROM Authors WHERE Author Like ‘d[a-e]*’
04/19/23 VBAN09 31
SQL CommandsORDER BY Clause Query results are sorted in either
ascending or descending order
SELECT * FROM Authors ORDER BY Author ASC
SELECT authorID, firstName, lastNameFROM AuthorsORDER BY lastName, firstName ASC
04/19/23 VBAN09 32
SQL CommandsINNER JOIN Merges Data from Multiple Tables
SELECT * FROM Authors INNER JOIN [Title Author] ONAuthors.Au_ID = [Title Author].Au_ID
The dot notation is necessary when the same field exists in two separate tables.
04/19/23 VBAN09 33
SQL CommandsINSERT Inserts a new record in a table
INSERT INTO tableName (field1, field2, …, fieldNameN )VALUES (value1, value2, …, valueN )
INSERT INTO Authors ( firstName, lastName )VALUES (‘Sue’, ‘Smith’ )
04/19/23 VBAN09 34
SQL CommandsUPDATE Modifies data in a table
UPDATE tableName SET field1 = value1, field2 = value2, …, fieldN = valueNWHERE criteria
UPDATE Authors SET lastName = ‘Jones’WHERE lastName = ‘Smith’ AND firstName = ‘Sue’
04/19/23 VBAN09 35
SQL CommandsDELETE Removes data from a table
DELETE FROM tableName WHERE criteria
DELETE FROM AuthorsWHERE lastName = ‘Jones’ AND firstName = ‘Sue’
04/19/23 VBAN09 36
Biblio.mdb Predefined Query
SELECT Titles.Title, Titles.ISBN, Authors.Author,Titles.[Year Published], Publishers.[Company
Name]FROM
Publishers INNER JOIN (Authors INNER JOIN ([Title Author] INNER JOIN Titles ON [Title Author].ISBN = Titles.ISBN) ON Authors.Au_ID = [Title Author].Au_ID)ON Publishers.PubID = Titles.PubIDORDER BY Titles.Title
04/19/23 VBAN09 37
ADO.Net
04/19/23 VBAN09 38
ADO.Net Data Objects
SelectCommand
InsertCommand
UpdateCommand
DeleteCommand
DataAdapter DataSet
Data Tables
DataTable DataTable
Data Rows Data Rows
Data Columns
Data Columns
Data Relations
Your Code
Database
Connection
04/19/23 VBAN09 39
Next?