Mark Dixon, SoCCE SOFT 131Page 1 12 – Databases: Structured Query Language.

Slides:



Advertisements
Similar presentations
Mark Dixon, SoCCE SOFT 131Page 1 22 – Object Oriented Analysis, Design, and Programming.
Advertisements

Mark Dixon Page 1 16 – Passing Data between pages: Forms, Sessions, & Query Strings.
Mark Dixon Page 1 05 – Database Design: Sub-forms.
Mark Dixon Page 1 04 – Database Design: Forms. Mark Dixon Page 2 Session Aims & Objectives Aims –To allow easier data entry using forms Objectives, by.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 17 – Persistent data storage: relational databases and ADO.
Mark Dixon, SoCCE SOFT 131Page 1 24 – Web applications: Writing data to Databases using ASP.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Modular Design in ASP.
Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.
Mark Dixon Page 1 03 – Database Design: Multiple Tables.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Expressions, Operators & Functions.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
Mark Dixon, SoCCE SOFT 131Page 1 20 – Web applications: HTML and Client-side code.
Mark Dixon, SoCCE SOFT 131Page 1 17 – Persistent data storage: relational databases and ADO.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Web applications: HTML and Client-side code.
Mark Dixon Page 1 SOFT – Module Introduction.
Mark Dixon Page 1 21 – Object Oriented Programming in ASP.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Entity-relationship diagrams.
Mark Dixon, SoCCE SOFT 131Page 1 22 – Web applications: Writing data to Databases using ASP.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Passing Data between pages: Sessions, Query Strings, & Self Posting.
Mark Dixon Page 1 18 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 02 – Queries: Query by Example.
Mark Dixon Page 1 20 – Modular Design in ASP. Mark Dixon Page 2 Session Aims & Objectives Aims –Highlight modular design techniques in ASP Objectives,
Mark Dixon, SoCCE SOFT 131Page 1 18 – Structured Query Language.
Mark Dixon Page 1 20 – Web applications: Writing data to Databases using ASP.
Mark Dixon, SoCCE SOFT 131Page 1 11 – Arrays of Structures & Modules.
Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)
Mark Dixon, SoCCE SOFT 131Page 1 19 – Web applications: Server-side code (ASP)
Mark Dixon, SoCCE SOFT 131Page 1 19 – Databases: Multiple Tables.
Mark Dixon, SoCCE SOFT 131Page 1 20 – Web applications: Writing data to Databases using ASP.
Mark Dixon Page 1 10 – Iterative Execution. Mark Dixon Page 2 Questions: Variables Write a line of code to declare a variable called h Write a line of.
Mark Dixon 1 20 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 5 – Persistent data storage: relational databases.
Interacting With Data Databases.
M Dixon 1 Web-Application Development Workshop. M Dixon 2 Session Aims & Objectives Aims –to introduce the main concepts involved in creating web-applications.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
Mark Dixon Page 1 24 – Object Oriented Programming in ASP.
Mark Dixon 1 22 – Web applications: Writing data to Databases using ASP.Net.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using ASP.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Dynamic HTML (client-side scripting)
Mark Dixon Page 1 18 – Web applications: Server-side code (PhP)
Mark Dixon Page 1 21 – Persistent data storage: relational databases and MySQL.
Mark Dixon 1 05 – JSP Databases: Multiple Tables.
Mark Dixon 1 06 – JSP Databases: Multiple Tables.
Lecture Note 10: Simple Database Techniques. Introduction –Database System –Access, SQL Server and others. –Microsoft Access - Interacting with this databases.
Mark Dixon Page 1 Web-Application Development Workshop.
Mark Dixon Page 1 21 – Web applications: Writing data to Databases using ASP.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Object Associations.
Mark Dixon, SoCCE SOFT 131Page 1 24 – Datatypes and Object Association.
Mark Dixon 1 21 – Databases: Multiple Tables. Mark Dixon 2 Questions: Databases How many records are in the following table? How many fields does the.
M Dixon 1 Web-Application Development Workshop. M Dixon 2 Session Aims & Objectives Aims –to introduce the main concepts involved in creating web-applications.
Mark Dixon 1 21 – Databases: Multiple Tables and Writing Data.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Dynamic HTML (client-side scripting)
M Dixon 1 Tech HTML. M Dixon 2 Admin Attendance Register: –log in to your profile.
Mark Dixon Page 1 Soft – HTML. Mark Dixon Page 2 Admin Attendance Register: –log in to your profile.
Mark Dixon Page 1 Tech – HTML. Mark Dixon Page 2 Admin Attendance Register: –log in to your profile.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Web applications: Databases & ASP.
Mark Dixon, SoCCE SOFT 131Page 1 18 – Enumerated Data Types and Arrays of Structures.
Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)
Mark Dixon 1 22 – Object Oriented Programming. Mark Dixon 2 Questions: Databases How many primary keys? How many foreign keys? 3 2.
Database Connectivity What is ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a Microsoft Active-X component.
CSC 405: Web Application Engineering II Course Preliminaries Course Objectives Course Objectives Students’ Learning Outcomes Students’ Learning Outcomes.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 6: Accessing a database with PHP Rob Gleasure robgleasure.com.
Mark Dixon, SoCCE SOFT 131Page 1 14 – Databases: Multiple Tables.
Mark Dixon Page 1 09 – Iterative Execution. Mark Dixon Page 2 Questions: Variables Write a line of VBScript code to declare a variable called h Write.
18 – Databases: Structured Query Language
Chapter 6 Displaying Your Products
17 – Persistent data storage: relational databases and ADO
19 – Databases: Multiple Tables
Presentation transcript:

Mark Dixon, SoCCE SOFT 131Page 1 12 – Databases: Structured Query Language

Mark Dixon, SoCCE SOFT 131Page 2 Session Aims & Objectives Aims –To introduce the fundamental ideas involved in using SQL Objectives, by end of this week’s sessions, you should be able to: –Use SQL in your programs to create more complex record-sets

Mark Dixon, SoCCE SOFT 131Page 3 Example: People Database Person PersonIDSurnameForenamesGenderPhone 1DixonMarkYes SmithJohnYes JonesSallyNo BloggsFredYes AndersonGennyNo SmithBobYes01752

Mark Dixon, SoCCE SOFT 131Page 4 Example: People v1 Display Surname of all people: <% Const cs = "…" Dim rs Set rs = CreateObject("ADODB.Recordset") rs.Open "Person", cs Do Until rs.EOF Response.Write rs.Fields("Surname").Value & " " rs.MoveNext Loop rs.Close Set rs = Nothing %>

Mark Dixon, SoCCE SOFT 131Page 5 Example: People v2 Display Surname of Male people: <% Const cs = "…" Dim rs Set rs = CreateObject("ADODB.Recordset") rs.Open "Person", cs Do Until rs.EOF If rs.Fields("Gender").Value = True Then Response.Write rs.Fields("Surname").Value & " " End If rs.MoveNext Loop rs.Close Set rs = Nothing %>

Mark Dixon, SoCCE SOFT 131Page 6 Example: People v3 Display Surname of Male people: <% Const cs = "…" Dim rs Set rs = CreateObject("ADODB.Recordset") rs.Open " SELECT * FROM Person WHERE Gender = True ", cs Do Until rs.EOF Response.Write rs.Fields("Surname").Value & " " rs.MoveNext Loop rs.Close Set rs = Nothing %> SQL statement

Mark Dixon, SoCCE SOFT 131Page 7 SQL: Queries main purpose of databases: –get information back out: searching Structured Query Language –dedicated to interacting with databases 3 rd Generation Language (such as VB, C++) –code describes how to do task 4 th Generation Language (such as SQL) –code describes what to do (not how to do it)

Mark Dixon, SoCCE SOFT 131Page 8 SQL: SELECT statement SELECT statement –used to get data –can be embedded in VB, via rs.Open: rs.Open "Person", cs rs.Open "SELECT * FROM [Person]", cs all fields

Mark Dixon, SoCCE SOFT 131Page 9 SQL: WHERE & ORDER BY WHERE clause –used to restrict data SELECT * FROM [People] WHERE [age]>=18; ORDER BY clause –used to change order of data SELECT * FROM [People] ORDER BY [Surname];

Mark Dixon, SoCCE SOFT 131Page 10 SQL: strings (text data) Possible confusion: SELECT * FROM Person WHERE Surname = Smith this will look for field called Smith - gives error need single (SQL) quotes to signify literal text SELECT * FROM Person WHERE Surname = 'Smith'

Mark Dixon, SoCCE SOFT 131Page 11 SQL & MS access queries MS Access –Queries: select data from database –really SQL select statements –can use queries to test SQL code MS Access: People.mdb

Mark Dixon, SoCCE SOFT 131Page 12 Example: Music Track TitleArtist NameCountry ParanoidBlack SabbathUK Falling in LoveAerosmithUS PinkAerosmithUS Love in an ElevatorAerosmithUS Smooth CriminalAlien Ant FarmUS Meaning of LifeDisturbedUS The GameDisturbedUS VoicesDisturbedUS Down with the SicknessDisturbedUS Track

Mark Dixon, SoCCE SOFT 131Page 13 Questions: SQL Create an SQL statement to extract Track Title of records by Aerosmith Track TitleArtist NameCountry ParanoidBlack SabbathUK Falling in LoveAerosmithUS PinkAerosmithUS Love in an ElevatorAerosmithUS Smooth CriminalAlien Ant FarmUS Meaning of LifeDisturbedUS The GameDisturbedUS VoicesDisturbedUS Down with the SicknessDisturbedUS Track SELECT [Track Title] FROM Track WHERE [Artist Name] = 'Aerosmith'; MS Access: Music.mdb

Mark Dixon, SoCCE SOFT 131Page 14 Questions: SQL Create an SQL statement to extract all fields of songs by Disturbed, ordered by track name Track TitleArtist NameCountry ParanoidBlack SabbathUK Falling in LoveAerosmithUS PinkAerosmithUS Love in an ElevatorAerosmithUS Smooth CriminalAlien Ant FarmUS Meaning of LifeDisturbedUS The GameDisturbedUS VoicesDisturbedUS Down with the SicknessDisturbedUS Track SELECT * FROM Track WHERE [Artist Name] = 'Disturbed' ORDER BY [Track Title]; MS Access: Music.mdb

Mark Dixon, SoCCE SOFT 131Page 15 Example: People v4 User controls what is displayed:

Mark Dixon, SoCCE SOFT 131Page 16 SQL: DISTINCT records SELECT [Artist Name] FROM [Track]; Artist Name Black Sabbath Aerosmith Alien Ant Farm Disturbed Artist Name Black Sabbath Aerosmith Alien Ant Farm Disturbed SELECT DISTINCT [Artist Name] FROM [Track];

Mark Dixon, SoCCE SOFT 131Page 17 Tutorial Exercise: People Task 1: Get the People (versions 1, 2, & 3) example (from the lecture) working. –Use the database you created last week. Task 2: Modify your code to include the phone number and address. Task 3: Get the People version 4 working. You will need to: –Add a form to the page, and 3 submit buttons –In your asp code, detect when a button has been pressed (have a look at previous weeks) Task 4: Modify your code so that the user can order the data by surname, or address. –You may want to use a Query String

Mark Dixon, SoCCE SOFT 131Page 18 Tutorial Exercise: Music Task 1: Create a web page to display the music database details. Task 2: Modify your code so that the user is presented with a list of artists, each of which is a link. When the user clicks an artist a list of tracks by that artist is displayed. (the list of artists must be generated dynamically from the database)