Mark Dixon, SoCCE SOFT 131Page 1 18 – Structured Query Language.

Slides:



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

Mark Dixon, SoCCE SOFT 131Page 1 22 – Object Oriented Analysis, Design, and Programming.
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, SoCCE SOFT 131Page 1 13 – Object Oriented Analysis, Design, and Programming.
Mark Dixon Page 1 03 – Database Design: Multiple Tables.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 06 – Iteration. Mark Dixon, SoCCE SOFT 131Page 2 Session Aims & Objectives Aims –Revise Variables and Conditional execution.
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.
ActiveX Data Object ISYS 562. ADO An ActiveX control ActiveX is build upon COM, a contract that defines a standard interface by which objects communicate.
Mark Dixon, SoCCE SOFT 131Page 1 15 – Object Associations.
Mark Dixon, SoCCE SOFT 131Page 1 17 – Persistent data storage: relational databases and ADO.
Mark Dixon, SoCCE SOFT 131Page 1 06 – Iteration. Mark Dixon, SoCCE SOFT 131Page 2 Session Aims & Objectives Aims –To introduce the main concepts involved.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Web applications: HTML and Client-side code.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Data-types, Variables, Operators & Functions.
Mark Dixon Page 1 SOFT – Module Introduction.
Mark Dixon, SoCCE SOFT 131Page 1 07 – Constants, Arrays, & Structures.
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 10 – Variable Scope, and Arrays of Structures.
Mark Dixon, SoCCE SOFT 131Page 1 22 – Web applications: Writing data to Databases using ASP.
Mark Dixon, SoCCE SOFT 131Page 1 08 – Iterative Execution.
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 12 – Enumerated Data-Types & Pass-by-reference.
Mark Dixon, SoCCE SOFT 131Page 1 13 – Control Arrays & Container Controls.
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, SoCCE SOFT 131Page 1 05 – Information Processing: Data-types, Variables, Operators & Functions.
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.
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 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, SoCCE SOFT 131Page 1 05 – Variables. Mark Dixon, SoCCE SOFT 131Page 2 Admin: Test (next week) In class test –teaching week 6 –university week.
Mark Dixon Page 1 21 – Web applications: Writing data to Databases using ASP.
Programming in R SQL in R. Running SQL in R In this session I will show you how to: Run basic SQL commands within R.
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.
Mark Dixon 1 21 – Databases: Multiple Tables and Writing Data.
AVCE ICT – Unit 7 - Programming Session 16 – Database and VB.
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.
Lab 8 Data Access Using Microsoft ActiveX Data Object (ADO)
Mark Dixon, SoCCE SOFT 131Page 1 12 – Databases: Structured Query Language.
Mark Dixon, SoCCE SOFT 131Page 1 17 – Procedures.
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.
Using a Database Access97 Please use speaker notes for additional information!
Visual Basic Database Programming.
18 – Databases: Structured Query Language
17 – Persistent data storage: relational databases and ADO
19 – Databases: Multiple Tables
Please see speaker notes for additional information!
Presentation transcript:

Mark Dixon, SoCCE SOFT 131Page 1 18 – 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 in list box: Option Explicit Const cs = "Provider … " Private Sub Form_Load() Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset rs.Open "Person", cs lstPeople.Clear Do Until rs.EOF lstPeople.AddItem rs.Fields("Surname").Value rs.MoveNext Loop rs.Close Set rs = Nothing End Sub

Mark Dixon, SoCCE SOFT 131Page 5 Example: People v2 Display Surname of Male people in list box: Option Explicit Const cs = "Provider …" Private Sub Form_Load() Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset rs.Open "Person", cs Me.lstPeople.Clear Do Until rs.EOF If rs.Fields("Gender").Value = True Then lstPeople.AddItem rs.Fields("Surname").Value End If rs.MoveNext Loop rs.Close Set rs = Nothing End Sub

Mark Dixon, SoCCE SOFT 131Page 6 Example: People v3 Display Surname of Male people in list box: Option Explicit Const cs = "Provider …" Private Sub Form_Load() Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset rs.Open " SELECT * FROM Person WHERE Gender = True ", cs Me.lstPeople.Clear Do Until rs.EOF lstPeople.AddItem rs.Fields("Surname").Value rs.MoveNext Loop rs.Close Set rs = Nothing End Sub 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 People Database (with Hobbies) IDSurnameForenamesPhone 1DixonMark SmithJohn JonesSally BloggsFred AndersonGenny01752 HobbyIDDescriptionPersonID 1Archery1 2Herpetology1 3Music1 4Football2 5Rugby2 6Hitting people with swords1 Hobby Person

Mark Dixon, SoCCE SOFT 131Page 13 SQL: Joining tables SELECT * FROM [Person], [Hobby] WHERE [Person].[ID] = [Hobby].[PersonID]; Two tables Matching records IDSurnameForenamesPhone HobbyIDDescriptionPersonID 1DixonMark DixonMark DixonMark DixonMark01752 people with swords1 2SmithJohn SmithJohn01752

Mark Dixon, SoCCE SOFT 131Page 14 SQL: Joining tables IDSurname 1Dixon Smith 2 SELECT [ID], [Surname] FROM [Person], [Hobby] WHERE [Person].[ID] = [Hobby].[PersonID];

Mark Dixon, SoCCE SOFT 131Page 15 SQL: DISTINCT records SELECT DISTINCT [ID], [Surname] FROM [Person], [Hobby] WHERE [Person].[ID] = [Hobby].[PersonID]; IDSurname 1Dixon 2Smith

Mark Dixon, SoCCE SOFT 131Page 16 Example: People v4 User controls what is displayed: Option Explicit Const cs = "Provider …" Private Sub optAll_Click() Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset rs.Open "Person", cs Me.lstPeople.Clear Do Until rs.EOF Me.lstPeople.AddItem rs.Fields("Surname").Value rs.MoveNext Loop rs.Close Set rs = Nothing End Sub Private Sub optMale_Click() ‘ You fill in this code. End Sub Private Sub optFemale_Click() ‘ You fill in this code. End Sub

Mark Dixon, SoCCE SOFT 131Page 17 Example: People v5 User controls what is displayed: –V4 has 38 lines –do same with 23 Option Explicit Const cs = "Provider …" Private Sub optAll_Click() ‘ You fill in this code. End Sub Private Sub optMale_Click() ‘ You fill in this code. End Sub Private Sub optFemale_Click() ‘ You fill in this code. End Sub