Database: SQL, MySQL, LINQ and Java DB ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

Slides:



Advertisements
Similar presentations
 2003 Prentice Hall, Inc. All rights reserved. Chapter 22 – Database: SQL, MySQL, DBI and ADO.NET Outline 22.1 Introduction 22.2 Relational Database Model.
Advertisements

Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
 Pearson Education, Inc. All rights reserved Accessing Databases with JDBC.
Introduction to Structured Query Language (SQL)
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
1 Introduction to Web Application Introduction to Data Base.
Introduction to Structured Query Language (SQL)
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Exercise SELECT authorID, lastName FROM authors AuthorID FirstName
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
With Microsoft Office 2007 Intermediate© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Intermediate.
With Microsoft Access 2007 Volume 1© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Access 2007 Volume 1 Chapter.
ASP.NET Programming with C# and SQL Server First Edition
Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
 2008 Pearson Education, Inc. All rights reserved Database: SQL, MySQL, ADO.NET 2.0 and Java DB.
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
A CCESSING D ATABASES WITH JDBC CH 24 C S 442: A DVANCED J AVA P ROGRAMMING.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
 2003 Prentice Hall, Inc. All rights reserved. 1 Java Database Connectivity with JDBC TM.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
Chapter 1 Overview of Database Concepts Oracle 10g: SQL
1 Chapter 1 Overview of Database Concepts. 2 Chapter Objectives Identify the purpose of a database management system (DBMS) Distinguish a field from a.
CHAPTER 8 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
CSC 2720 Building Web Applications Database and SQL.
Database: SQL and MySQL
1 Databases November 15, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg. Published.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 6 Web Server & database.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Databases MIS 21. Some database terminology  Database: integrated collection of data  Database Management System (DBMS): environment that provides mechanisms.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Ch Determine the output displayed from procedures Lab sheet 10.4.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
IST 220 Introduction to Databases Course Wrap-up.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved. 2 Revised by Dr. T. Tran for CSI3140.
 2005 Pearson Education, Inc. All rights reserved Accessing Databases with JDBC.
A CCESSING D ATABASES WITH JDBC CH 24 C S 442: A DVANCED J AVA P ROGRAMMING.
 2008 Pearson Education, Inc. All rights reserved Database: SQL, MySQL, ADO.NET 2.0 and Java DB.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 22 - SQL, MySQL, DBI and ADO Outline 22.1 Introduction 22.2 Relational Database Model 22.3 Relational.
 2009 Pearson Education, Inc. All rights reserved Databases and LINQ to SQL.
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
LINQ to DATABASE-2.  Creating the BooksDataContext  The code combines data from the three tables in the Books database and displays the relationships.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
ORDER BY Clause The result of a query can be sorted in ascending or descending order using the optional ORDER BY clause. The simplest form of.
Fundamentals of DBMS Notes-1.
Database, SQL and ADO.NET
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Chapter 5 Introduction to SQL.
 2012 Pearson Education, Inc. All rights reserved.
LINQ to DATABASE-2.
JDBC.
Databases Intro (from Deitel)
The University of Texas – Pan American
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Chapter 22 - SQL, MySQL, DBI and ADO
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.

Internet & World Wide Web How to Program, 5/e

© by Pearson Education, Inc. All Rights Reserved.

 A database is an organized collection of data.  A database management system (DBMS) provides mechanisms for storing, organizing, retrieving and modifying data for many users.  Today’s most popular database management systems are relational databases.  SQL is the international standard language used almost universally with relational database systems to perform queries and manipulate data.  Programs connect to, and interact with, relational databases systems via an interface—software that facilitates communications between a database management system and a program. © by Pearson Education, Inc. All Rights Reserved.

 A relational database stores data in tables. Tables are composed of rows, and rows are composed of columns in which values are stored.  A primary key provides unique values that cannot be duplicated in other rows of the same table.  Each column of a table represents a different attribute in a row of data.  The primary key is a column (or group of columns) with a unique value that cannot be duplicated in other rows. © by Pearson Education, Inc. All Rights Reserved.

 The combined columns of the AuthorISBN table represent the table’s primary key—thus, each row in this table must be a unique combination of an AuthorID and an ISBN.  This is known as the Rule of Entity Integrity.  A one-to-many relationship between tables indicates that a row in one table can have many related rows in a separate table.  A foreign key is a column in a table that matches the primary-key column in another table.  The foreign key helps maintain the Rule of Referential Integrity: Every foreign-key value must appear as another table’s primary-key value. © by Pearson Education, Inc. All Rights Reserved.

 Foreign keys also allow related data in multiple tables to be selected from those tables for analytic purposes—this is known as joining the data. © by Pearson Education, Inc. All Rights Reserved.

 An entity-relationship (ER) diagram shows the database tables and the relationships among them.  Every row must have a primary-key value, and that value must be unique in the table. This is known as the Rule of Entity Integrity.  An infinity symbol (∞) indicates a one-to-many relationship, in which an entry from a table can have an arbitrary number of entries in another table.  A many-to-many relationship indicates that multiple entries can be related between tables. © by Pearson Education, Inc. All Rights Reserved.

 The next several subsections discuss the keywords listed in the following slide in the context of SQL queries and statements. © by Pearson Education, Inc. All Rights Reserved.

 The basic form of a SELECT query is SELECT * FROM tableName in which the asterisk ( * ) wildcard character indicates that all columns from the tableName should be retrieved.  To retrieve specific columns, replace the * with a comma-separated list of column names.  p p © by Pearson Education, Inc. All Rights Reserved.

 SQL uses the optional WHERE clause in a query to specify the selection criteria for the query. The basic form of a query with selection criteria is SELECT columnName1, columnName2, … FROM tableName WHERE criteria  Strings in SQL are delimited by single (') rather than double (") quotes.  © by Pearson Education, Inc. All Rights Reserved.

Pattern Matching: Zero or More Characters  The WHERE clause can contain operators, =, =, <> and LIKE. Operator LIKE is used for string pattern matching with wildcard characters percent ( % ) and underscore ( _ ).  A percent character ( % ) in a pattern indicates that a string matching the pattern can have zero or more characters at the percent character’s location in the pattern.  An underscore ( _ ) in the pattern string indicates a single character at that position in the pattern. © by Pearson Education, Inc. All Rights Reserved.

Pattern Matching: Any Character  An underscore ( _ ) in the pattern string indicates a single wildcard character at that position in the pattern.  The following query locates the rows of all the authors whose last names start with any character (specified by _), followed by the letter o, followed by any number of additional characters (specified by %): SELECT AuthorID, FirstName, LastName FROM Authors WHERE LastName LIKE '_o%'  The preceding query produces the row shown in the next slide, because only one author in our database has a last name that contains the letter o as its second letter. © by Pearson Education, Inc. All Rights Reserved.

  ds.asp ds.asp

 The result of a query can be sorted in ascending or descending order using the optional ORDER BY clause. The simplest form of an ORDER BY clause is SELECT columnName1, columnName2, … FROM tableName ORDER BY column ASC SELECT columnName1, columnName2, … FROM tableName ORDER BY column DESC where ASC specifies ascending order, DESC specifies descending order and column specifies the column on which the sort is based. The default sorting order is ascending, so ASC is optional.  Multiple columns can be used for ordering purposes with an ORDER BY clause of the form ORDER BY column1 sortingOrder, column2 sortingOrder, …  The WHERE and ORDER BY clauses can be combined in one query. If used, ORDER BY must be the last clause in the query.  © by Pearson Education, Inc. All Rights Reserved.

 An INNER JOIN operator merges rows from two tables by matching values in columns that are common to the tables. The basic form for the INNER JOIN operator is: SELECT columnName1, columnName2, … FROM table1 INNER JOIN table2 ON table1.columnName = table2.columnName  The ON clause of the INNER JOIN specifies the columns from each table that are compared to determine which rows are merged.  The following query produces a list of authors accompanied by the ISBNs for books written by each author: SELECT FirstName, LastName, ISBN FROM Authors INNER JOIN AuthorISBN ON Authors.AuthorID = AuthorISBN.AuthorID ORDER BY LastName, FirstName © by Pearson Education, Inc. All Rights Reserved.

 Note the use of the syntax tableName.columnName in the ON clause. This syntax, called a qualified name, specifies the columns from each table that should be compared to join the tables.  The “tableName.” syntax is required if the columns have the same name in both tables. The same syntax can be used in any SQL statement to distinguish columns in different tables that have the same name.  In some systems, table names qualified with the database name can be used to perform cross-database queries. As always, the query can contain an ORDER BY clause.  © by Pearson Education, Inc. All Rights Reserved.

 An INSERT statement inserts a new row into a table. The basic form of this statement is INSERT INTO tableName ( columnName1, columnName2, …, columnNameN ) VALUES ( value1, value2, …, valueN ) where tableName is the table in which to insert the row. The tableName is followed by a comma-separated list of column names in parentheses. The list of column names is followed by the SQL keyword VALUES and a comma-separated list of values in parentheses.  Always explicitly list the columns when inserting rows. If the table’s column order changes or a new column is added, using only VALUES may cause an error. © by Pearson Education, Inc. All Rights Reserved.

 The INSERT statement INSERT INTO Authors ( FirstName, LastName ) VALUES ( 'Sue', 'Red' ) inserts a row into the Authors table.  The statement indicates that values are provided for the FirstName and LastName columns.  The corresponding values are 'Sue' and ‘Red'.  We do not specify an AuthorID in this example because AuthorID is an autoincremented column.  For every row added to this table, the DBMS assigns a unique AuthorID value that is the next value in the autoincremented sequence (i.e., 1, 2, 3 and so on). In this case, Sue Red would be assigned AuthorID number 6.  © by Pearson Education, Inc. All Rights Reserved.

 An UPDATE statement modifies data in a table. Its basic form is UPDATE tableName SET columnName1 = value1, columnName2 = value2, …, columnNameN = valueN WHERE criteria where tableName is the table in which to update data. The tableName is followed by keyword SET and a comma-separated list of column name/value pairs in the format columnName = value. The optional WHERE clause criteria determines which rows to update. © by Pearson Education, Inc. All Rights Reserved.

 A SQL DELETE statement removes rows from a table. Its basic form is DELETE FROM tableName WHERE criteria where tableName is the table from which to delete a row (or rows). The optional WHERE criteria determines which rows to delete. If this clause is omitted, all the table’s rows are deleted. © by Pearson Education, Inc. All Rights Reserved.

 The CREATE TABLE statement is used to create a table in a database.  Tables are organized into rows and columns; and each table must have a name.  CREATE TABLE table_name ( column_name1 data_type(size), column_name2 data_type(size), column_name3 data_type(size),.... ); © by Pearson Education, Inc. All Rights Reserved.

 CREATE TABLE Persons ( PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) ); © by Pearson Education, Inc. All Rights Reserved.