Introduction to Databases: DB Review & ADO.NET Models – Connected and Disconnected

  • View

  • Download

Embed Size (px)


Introduction to Databases: DB Review & ADO.NET Models Connected and Disconnected. Introduction to Databases. A database is a collection of data related to a particular topic. Databases can range from a few kilobytes to several terabytes and beyond. - PowerPoint PPT Presentation



Introduction to Databases: DB Review & ADO.NET Models Connected and Disconnected

1Introduction to DatabasesA database is a collection of data related to a particular topic.Databases can range from a few kilobytes to several terabytes and beyond.The Integrated Student Information System (ISIS) used at Uludag University is a large database. Googles database is an example of a massive database.NSA has a massive database called a data warehouse that collects information from a variety of other databases. Social Security has massive data base imagine what is stored here

A Database Management System (DBMS) is software that is used to create, access and maintain a database.Microsoft AccessMicrosoft SQL ServerOracle

Introduction to DatabasesA relational database stores data and the connections (relationships) within the data.It uses a relational data model.

A relational database uses tables to store data and manipulate it.A table can be visualized as a 2-dimensional grid that contains rows and columns.

Each table contains one or more records (rows) that contain information about a single entry.Records contain a set of related fields that are used to store data.

Each record contains one or more fields (columns) that contain a single piece of data.

Introduction to DatabasesA table represents an entity in a problem domain.For example, in the integrated system information system ISIS, a table may represent a student entity or a course entity

A record is an instance of an entity.In ISIS, a specific student record (you, for example) would be an instance of the student entity (table).Also, a specific course CIS3309 Section 001 would be an instance of the course entity. Database Tables are models of application domain entities those things that need to be manipulated in our systemThese things are no different in concept from the entities we model in VBOnly here we use classes for our models rather than DB Tables

Introduction to DatabasesMost tables include a primary key, which is a field that uniquely identifies each record in a table.Storing student records by name in a large university will make it difficult to find students with the same name. Giving each student a StudentID uniquely identifies each student.SSN uniquely identify each American in the U.S.

The tables in a relational database are related to each other through their key columns. A column that identifies a related row in another table is called a foreign key.

Illustration Primary and Foreign Keys

Product TableIntro to Databases Naming ConventionsA database named Employees with one table named tblEmployees containing the following fields:

fldEmployeeID (number) unique employee id numberfldFirstName and fldLastName (strings) employee's first and last name, respectivelyfldTelephone (string or number) the employee's telephone numberfldDateHired (date value) stores date that the employee was hiredfldWage (number) contains the hourly wage for the employeefldDeductions (number) contains the number of tax deductions claimed by the employeefldNotes is a string containing notes pertaining to the employeefldStatus (Boolean) If True the employee is still employed. If False the employee is a former employee.fldType (string) employee (valid values: fulltime and parttime)

7Populated Database Table

8Naming Database Tables and FieldsStandard (Hungarian) prefixes are commonly used to name database tables and fieldsThe prefix "tbl" denotes a tableThe prefix "fld" denotes a field9Relational DatabasesData stored in one table can be related to data stored in another table in a few ways:One-To-One RelationshipOne-To-Many Relationship.Many-To-Many Relationship.

One-To-Many Relationship means a record in one table is related to many records in another table via primary and foreign keys.For example, a course record in the Course table for Temple university can relate to many students in the Student table.

Relational DatabasesMany-To-Many Relationship means a record in Table A can have many records in Table B, and vice versa.It can be thought of as two separate one-to-many relationships.For example, a writer can write many books, and a book can have many writers.Thus, a Book table can contain a record that relates to an Author table by having multiple authors for a book, and an author record in the Author table can relate to the Book table by having a author that wrote many books.Student-course example?What do we do to many-many relationships? One-many. Many-one.

One-To-One Relationship means a record in one table is related to one and only one record in another table.For example, an employee has a single resume, and each resume only belongs to one employee.

Introduction to SQLStructured Query language (SQL) is an English like language that is used to manage and manipulate data in the database.

There are 4 basic SQL statements that are needed to work with data in a database.SELECT used to query a table and find specific information based on some criteria. It selects one or more rows (records) from a table.INSERT used to add one or more rows (records) to a table.UPDATE used for modifying data in one or more rows (records) in a table.DELETE used to delete one or more rows (records) in a table.SQL: Select StatementThe result of a Select statement is called a result set, or result table, which is a logical set of rows that consists of all of the columns and rows requested by the Select statement.

Syntax:SELECT column_name [, column_name2]...FROM table_name[WHERE selection-criteria][ORDER BY column_name [ASC|DESC] [, column_name2[ASC|DESC]]...]

SQL: Select Statement ExampleExample:SELECT ProductID, Name, UnitPriceFROM ProductsWHERE CategoryID = propsORDER BY UnitPrice DESC

The asterisk (*) can be usedto select all fields of a table.Example:SELECT * FROM Products

Result Set shown above. Click button to view full table.SQL: Insert StatementThe Insert statement is used to add a new row (record) to a table. It can be used to set fields to specified values as it adds the new record.

Syntax:INSERT [INTO] table_name [(columns_list)]VALUES (values_list)

The order of the items in columns list must match the order of the items in the values list.SQL: Insert Statement ExampleExample:INSERT INTO Products (ProductID, ShortDescription, UnitPrice) VALUES (p101, Toy, 19.99)

SQL: Update StatementThe Update statement is used to modify/edit existing data within a table.

Syntax:UPDATE table_nameSET column_name = value [, column_name2 = value 2]...WHERE selection-criteriaSyntax:UPDATE ProductsSET UnitPrice = 25.79, OnHand = 3 WHERE ProductID=arm01

SQL: Delete StatementThe Delete statement is used to remove a row or rows from a table.

Syntax:DELETE FROM table_name WHERE selection-criteriaExample:DELETE FROM ProductsWHERE ProductID = arm01

Introduction to DB Access in VS - ADO.NETThe ActiveX Data Objects (ADO.NET) is part of the .NET framework that provides a multi-layered set of data access namespaces (set of classes), which allow us to access and modify data stored in a database.

ADO.NET is the primary data access API for the .NET framework.It is a framework inside a framework.This frameworks responsibility is to allow our programs to work with databases by providing the abstraction against which we can program

ADO.NET supports many different database platforms

ADO.NET supports both a connected and disconnected data architecture.ADO.NET LibrariesADO.NET supports multiple database platformsSqlClient provides support for Microsoft SQL Server 7.0 and later. Import System.Data.SqlClient

OracleClient provides support for Oracle 8.1.7 and later.Import System.Data.OracleClient

OleDb (Object Linking & Embedding) provides support for conecting to OleDb sources like SQL server, Oracle, and Jet 4.0 (Access).Import System.Data.OleDb

ODBC (Object Database Connection) provides support for connection to ODBC source. Only used when you are not connecting to an OleDb source.Import System.Data.ODBC

The ADO.Net PlatformsMicrosoft JET Database Engine (Jet) is a database engine that is the main component for storing, parsing, optimizes, and processes queries.Jet stands for Joint Engine Technology and it is now part of the Windows operating system.The database engine used for Microsoft Access DBMS 2003 and earlier.It is a File-Server System DBMS where the work is done on the individual computer where the Access DBMS exists.

Microsoft SQL Server is a client-server DBMS in which the client requests information from the database and the server processes the request.Provides functionalities beyond those available through Jet.Improved multi-user access and transaction-based processing.

The ADO.NET Platforms - 2Microsoft ACE Database Engine (Ace) is a database engine for the Access DBMS 2007 and later.Newest database engine for working with Access .accdb files.

Oracle is another client-server DBMS used for large databases.

Visual Studio & .NET have tools for working with all these database management systems.These tools are part of the sub-namespaces of the System.Data namespaceMore on ADO.NETADO.NET has three main abstractions:DataProvidersDataSetsDataReaders

The ADO.NET DataProviders are components (namespaces containing classes) specifically designed for working with a particular database platform.There is a namespace (a set of classes) for working with Access, SQL Server, one set specifically for Oracle, etcThe ADO.NET DataSet is a component used for working with data separate from the data source.An integral part of the disconnected data architecture.The ADO.NET DataReader is an abstraction t