Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 9 Structured Query Language David M. Kroenke Database Processing © 2000 Prentice Hall.

Similar presentations


Presentation on theme: "Chapter 9 Structured Query Language David M. Kroenke Database Processing © 2000 Prentice Hall."— Presentation transcript:

1 Chapter 9 Structured Query Language David M. Kroenke Database Processing © 2000 Prentice Hall

2 Chapter 9 © 2000 Prentice Hall SQL “Structured Query Language; standard language for relational data manipulation” DB2, SQL/DS, Oracle INGRES, SYBASE, SQL Server dBase/Win, Paradox, Access Page 217

3 Chapter 9 © 2000 Prentice Hall Introduction to SQL IBM in the mid-1970s as SEQUEL SQ92 = 1992 ANSI standard data access language that is embedded in application programs result of an SQL statement is a relation Page 217

4 Sample Data Figure 9-2 © 2000 Prentice Hall

5 Chapter 9 © 2000 Prentice Hall Projection SELECT SID, Name, Major FROM STUDENT Page 219

6 Chapter 9 © 2000 Prentice Hall Selection SELECT SID, Name, Major, GradeLevel, Age FROM STUDENT WHERE Major = ‘MATH’ Page 220

7 Chapter 9 © 2000 Prentice Hall Selection SELECT * FROM STUDENT WHERE Age Between 19 and 30 Page 222

8 Chapter 9 © 2000 Prentice Hall Sorting SELECT Name, Major, Age FROM STUDENT WHERE Major = ‘ACCOUNTING’ ORDER BY Name Page 223

9 Chapter 9 © 2000 Prentice Hall SQL Built-In Functions SELECT COUNT(Major) FROM STUDENT Page 223

10 Chapter 9 © 2000 Prentice Hall Grouping SELECT Major, COUNT(*) FROM STUDENT GROUP BY Major HAVING COUNT(*) > 1 Page 224

11 Chapter 9 © 2000 Prentice Hall Querying Multiple Tables Retrieval Using Subquery Joining with SQL Page 226

12 Chapter 9 © 2000 Prentice Hall Subquery (the second SELECT) SELECT Name FROM STUDENT WHERE SID IN (SELECT StudentNumber FROM ENROLLMENT WHERE ClassName = ‘BD445’) Page 226

13 Chapter 9 © 2000 Prentice Hall Joining with SQL SELECT STUDENT.SID, STUDENT.Name, ENROLLMENT.ClassName FROM STUDENT, ENROLLMENT WHERE STUDENT.SID = ENROLLMENT.StudentNumber Page 227

14 Chapter 9 © 2000 Prentice Hall Outer Join SELECT Name, ClassName FROM STUDENT LEFT JOIN ENROLLMENT ON SID = StudentNumber; (note semicolon notation) Page 230

15 Chapter 9 © 2000 Prentice Hall Exists and Not Exists “Logical operators whose value is either true or false depending on the presence or absence of rows that fit the qualifying conditions” Page 230

16 Chapter 9 © 2000 Prentice Hall Exist SELECT DISTINCT StudentNumber FROM ENROLLMENT A WHERE EXISTS (SELECT * FROM ENROLLMENT B WHERE A.StudentNumber = B.StudentNumber AND A.ClassName NOT = B.ClassName) Page 230

17 Chapter 9 © 2000 Prentice Hall Changing Data Inserting Data INSERT INTO ENROLLMENT VALUES (400, ‘BD445’, 44) Deleting Data DELETE STUDENT WHERE STUDENT.SID = 100 Modifying Data UPDATE ENROLLMENT SET PositionNumber = 44 WHERE SID = 400 Page 232


Download ppt "Chapter 9 Structured Query Language David M. Kroenke Database Processing © 2000 Prentice Hall."

Similar presentations


Ads by Google