Relational Databases, SQL and ADO.NET in 75 minutes



Similar documents
ASP.NET Programming with C# and SQL Server

Deleting A Record Updating the Database Binding Data Tables to Controls Binding the Data Table to the Data Grid View...

VB.NET - DATABASE ACCESS

AD A O.N. ET E Access Data Object

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

A basic create statement for a simple student table would look like the following.

Revolutionized DB2 Test Data Management

DbSchema Tutorial with Introduction in SQL Databases

var context = new CustomerContext(); //... context code...

Beginning C# 5.0. Databases. Vidya Vrat Agarwal. Second Edition

Visual Basic. murach's TRAINING & REFERENCE

Developing Web Applications for Microsoft SQL Server Databases - What you need to know

MySQL for Beginners Ed 3

SQL Injection Vulnerabilities in Desktop Applications

Using Temporary Tables to Improve Performance for SQL Data Services

Advantage Database Server

Relational Database Basics Review

Mastering Visual Basic.NET Database Programming Evangelos Petroutsos; Asli Bilgin

How-To: MySQL as a linked server in MS SQL Server

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

A Brief Introduction to MySQL

SQL 2: GETTING INFORMATION INTO A DATABASE. MIS2502 Data Analytics

Accessing Your Database with JMP 10 JMP Discovery Conference 2012 Brian Corcoran SAS Institute

Relational model. Relational model - practice. Relational Database Definitions 9/27/11. Relational model. Relational Database: Terminology

SQL. Short introduction

Guide to Performance and Tuning: Query Performance and Sampled Selectivity

MOC 20461C: Querying Microsoft SQL Server. Course Overview

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

Mul$media im Netz (Online Mul$media) Wintersemester 2014/15. Übung 03 (Nebenfach)

Exposed Database( SQL Server) Error messages Delicious food for Hackers

Microsoft Access Lesson 5: Structured Query Language (SQL)

Oracle Database 12c: Introduction to SQL Ed 1.1

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. Introduction to Databases. Why databases? Why not use XML?

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

Chapter 3. Data Analysis and Diagramming

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

Concepts Design Basics Command-line MySQL Security Loophole

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

Title. Syntax. stata.com. odbc Load, write, or view data from ODBC sources. List ODBC sources to which Stata can connect odbc list

Chapter 6: Physical Database Design and Performance. Database Development Process. Physical Design Process. Physical Database Design

CHAPTER 23: USING ODBC

The release notes provide details of enhancements and features in Cloudera ODBC Driver for Impala , as well as the version history.

How to test and debug an ASP.NET application

ICOM 6005 Database Management Systems Design. Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 August 23, 2001

Intro to Databases. ACM Webmonkeys 2011

Understanding Sql Injection

Microsoft Access 3: Understanding and Creating Queries

Information Systems SQL. Nikolaj Popov

Physical Database Design Process. Physical Database Design Process. Major Inputs to Physical Database. Components of Physical Database Design

Serious Threat. Targets for Attack. Characterization of Attack. SQL Injection 4/9/2010 COMP On August 17, 2009, the United States Justice

Object Oriented Databases. OOAD Fall 2012 Arjun Gopalakrishna Bhavya Udayashankar

Facebook Twitter YouTube Google Plus Website

3.GETTING STARTED WITH ORACLE8i

Database Application Developer Tools Using Static Analysis and Dynamic Profiling

CS 2316 Data Manipulation for Engineers

SQL SELECT Query: Intermediate

Testing Web Applications for SQL Injection Sam Shober

Financial Management System

MapInfo SpatialWare Version 4.6 for Microsoft SQL Server

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL)

Getting Started with User Profile Data Modeling. White Paper

Oracle SQL. Course Summary. Duration. Objectives

Web Application Disassembly with ODBC Error Messages By David Litchfield Director of Security

Crystal Reports for Visual Studio.NET

Database Query 1: SQL Basics

Integrating VoltDB with Hadoop

Files. Files. Files. Files. Files. File Organisation. What s it all about? What s in a file?

The Data Access Handbook

Oracle Database 10g Express

Achieving Database Interoperability Across Data Access APIs through SQL Up-leveling

Oracle Database: SQL and PL/SQL Fundamentals NEW

White Paper. Blindfolded SQL Injection

David M. Kroenke and David J. Auer Database Processing 11 th Edition Fundamentals, Design, and Implementation. Chapter Objectives

Performance Tuning for the Teradata Database

Detail Report Excel Guide for High Schools

Architecting the Future of Big Data

Qlik REST Connector Installation and User Guide


Oracle Database: SQL and PL/SQL Fundamentals

Raima Database Manager Version 14.0 In-memory Database Engine

Oracle Database: SQL and PL/SQL Fundamentals

NATIONAL STUDENT CLEARINGHOUSE RESEARCH CENTER

Teradata SQL Assistant Version 13.0 (.Net) Enhancements and Differences. Mike Dempsey

SAP Business Objects Business Intelligence platform Document Version: 4.1 Support Package Data Federation Administration Tool Guide

David M. Kroenke and David J. Auer Database Processing 12 th Edition

Using IRDB in a Dot Net Project

Increasing Driver Performance

Using AND in a Query: Step 1: Open Query Design

Building ASP.NET Applications

Physical Design. Meeting the needs of the users is the gold standard against which we measure our success in creating a database.

Spark ΕΡΓΑΣΤΗΡΙΟ 10. Prepared by George Nikolaides 4/19/2015 1

Once the schema has been designed, it can be implemented in the RDBMS.

ADP Workforce Now V3.0

ODBC Chapter,First Edition

Transcription:

Relational Databases Relational Databases, SQL and ADO.NET in 75 minutes Data is organized into tables with rows and columns A row is a single instance of a record Columns are the attributes of a record Tables can be linked in relationships Keys / Indexes Keys are columns or groups of columns that are Indexed to make find / sorting them faster Index can be unique or allow duplicates One key (one or more columns) can be primary, must be unique Organizing data (schema) How data (tables, rows, columns) are organized in a database is its schema Data is organized best when it is organized in a normal form You will be given existing tables so understanding normal forms is not necessary Please take CS 564 for more information Relationships Only type of relationship discussed here is a link where rows / records in two tables share a common column / attribute Table 1: UID, Name Table 2: UID, Grade1 UID, Grade2 etc. Find Joe s name and grades where the UID in both tables refers to Joe. SQL Structured Query Language A few words that impact your life every day We will focus on 4 commands Select Insert Update Delete 1

Quotation Specifying data in SQL commands are very fragile with respect to use of quotation marks If specifying SQL commands from a program use parameterized arguments to avoid the problem Parameterized arguments are discussed later select Select columns from tables where certain conditions are true plus some options Select all columns, all records: select * from t; Select all columns, some records select * from t where age > 21; Select all columns, some records, w/ options select * from t where age > 21 order by lastname; select Select some columns select firstname, lastname from t; Select on more than one condition select * from t where age > 21 and age < 75; Usual logical operators for conditions String columns can be pattern matched select firstname where firstname like %th% ; select Select (and summarize) by group select count(state),state from t group by state; Select unique values select distinct state from t order by state; See: http://dev.mysql.com/doc/refman/5.1/en/sql-syntax.html Selecting from more than one table - Join There are several types of joins. We only look at the inner join (simply use, between table names) Cross product of two tables (hopefully) limited by some constraint select id, name, ordernumber from customers, orders where customers.id = orders.customerid order by id; If there is a column with the same name in two tables, you must disambiguated explicitly insert insert into tbl set columnname=value; Multiple columns can be set separated by, Value can be default if column has a default If there is a collision of a unique key, an error results Use ignore syntax if you don t care insert ignore into t set id=29; See http://dev.mysql.com/doc/refman/5.1/en/insert.html 2

update update [ignore] tbl set id=9 where id=6 Multiple columns may be set separated by, Compound where conditions may be used Note the optional ignore if you are changing a key value that is supposed to be unique and a collision occurs See http://dev.mysql.com/doc/refman/5.1/en/insert.html delete delete [ignore] from tbl where id=9; Don t leave out the where condition unless you want to delete all records (not in this class) Note optional ignore to ignore errors Multiple where conditions may be specified See http://dev.mysql.com/doc/refman/5.1/en/delete.html ADO.NET Active Data Objects for.net Object oriented wrapper to database methods and data structures We will use ODBC version of methods Open Database Connectivity Independent of database backend Typical flow Define connection the connection string Open the connection Issue commands, receive / transmit data Close the connection Connection string MySQL version DRIVER={MySQL ODBC 3.51 Driver}; SERVER=oberon.cs.wisc.edu; PORT=3400; DATABASE=databaseName; USER=userName; PASSWORD=myPassword; OPTION=3;" One long string Each of you will get your own copy of the database {MySQL ODBC 3.51 Driver}; Refers to the MySQL connector which must be installed on your system Will be preloaded on instructional machines Found here: http://dev.mysql.com/downloads/connector/odbc/3.51.html 3

Connection object Instantiate an OdbcConnection Pass connection string to constructor Will use: Methods Open open the connection CreateCommand create command objects Close close the connection Attributes State Connection object Remember to close an open connection Nice use of finally Or web page s Unload function discussed in future lecture Use open / close judiciously as operation is high overhead Command object Instantiate OdbcCommand object either by constructor or connection object CreateCommand If you use the constructor, you need to specify the connection object to the Connection attribute Specify command in CommandText Use parameterized queries! Command.Parameters.AddWithValue() Parameterized queries If any part of a SQL command can come from user input, avoid SQL injection attacks by using parameterized queries Example: select c2 from t where c1 = ; substitute 1; drop table t What happens? Parameterized queries Cleaner looking code Eliminates the headache of proper quoting ExecuteNonQuery() Used for executing SQL commands which do not return a row or rows of data such as: insert delete update 4

ExecuteScalar() Used to return exactly one column of one row Frequent example: Getting a count of some set of rows Returns instance of Object Return value must be converted to the appropriate type ExecuteReader() Used to retrieve a row or rows one at a time Uses little memory Sequential forward-only access Ties up connection as long as it is open ExecuteReader() ExecuteReader() Access columns using index or column name All columns are returned as Objects Results must be cast with System.Convert Which do you think is higher performance? DataTables, DataSets You may use this paradigm if you wish See hidden slides Glossed over here DataAdapter Bridge between the data source and a DataSet object (discussed next) Two methods most important: Fill connects to database, fills a DataSet from the database, then disconnects Update computes update needs, connects to a database, updates the database, then disconnects 5

DataSet Memory-resident object oriented representation of a database Being memory-resident: is fast can be randomly accessed potentially large memory cost Perhaps overkill for many web applications? DataTable Made up of DataRows (Rows) and DataColumns (Columns) Rows can be accessed by index Column data can be accessed by index or name Column data are of type Object must be converted with System.Convert Has select capability (but different syntax) CommandBuilder Filling a DataTable Generates single table SQL commands for use with DataAdapter.Update( ) Insert, Delete, Update Now for some examples Accessing Row Data Updating, Deleting, Inserting 6

Changes Not Committed Yet! Summary Reader Vs. Set DataReader One way, sequential Memory efficient DataSet Memory resident view of database Fast random access Can be expensive Permits definition of table relationships (not covered in this course) Important subject not covered! I have not covered concurrency issues at all Should not be an issue because each of you get your own database 7