Presentation is loading. Please wait.

Presentation is loading. Please wait.

Oct 2001 cylauFoxpro Chapter 91 Chapter 9 SQL Structural Query Language.

Similar presentations


Presentation on theme: "Oct 2001 cylauFoxpro Chapter 91 Chapter 9 SQL Structural Query Language."— Presentation transcript:

1 Oct 2001 cylauFoxpro Chapter 91 Chapter 9 SQL Structural Query Language

2 Oct 2001 cylauFoxpro Chapter 92 Properties zSet-oriented database language zUsed to manipulate and retrieve data from relational database zNon-procedural language (what, not how) yA procedural language stresses on HOW. yA non-procedural language stresses on What. z4GL (Fourth Generation Language) zPowerful (a few commands can do lots of work)

3 Oct 2001 cylauFoxpro Chapter 93 Syntax zA simple subset of SQL SELECT (some fields)&& Not the SELECT in FoxPro FROM (a table) ORDER BY (some fields) TO (some place) zThe SQL command SELECT is not the same as the Foxpro command SELECT zSQL - SELECT is used for data retrieval zFoxpro - SELECT is used for choosing a work area

4 Oct 2001 cylauFoxpro Chapter 94 Example zFurther Practice 15 Q.3 SELECT * && all fields FROM payroll ORDER BY staff_id, year, month zTwo tables will be opened ythe table payroll ythe cursor

5 Oct 2001 cylauFoxpro Chapter 95 Cursor zThe result of a query is called a Cursor zA non-editable table zFor browsing or reporting zA browsing window appears when no TO clause or INTO clause is present

6 Oct 2001 cylauFoxpro Chapter 96 A Larger Subset of SQL SELECT [DISTINCT] fieldName1| expr1 [AS aliasName1] [, fieldName2| expr2 AS aliasName2] FROM tableName [ORDER BY fieldname1|aliasName1 [ASC|DESC] [fieldname1|aliasName1 [ASC|DESC]]] [TO SCREEN|TO PRINTER|TO textfile|INTO TABLE tablename] zItems inside […] may be omitted zchoice1 | choice2 | … | choiceN&& take ONE choice

7 Oct 2001 cylauFoxpro Chapter 97 Example zSTUDENT(class, no, name, house, result) 7A01ChanLove13.3 7A15LeeFaith13.8 7A09CheungWisdom12.9 7S38WongHope13.1 7S12HoFaith14.2

8 Oct 2001 cylauFoxpro Chapter 98 Select Individual Columns zSELECT name, class FROM student NameClass Chan7A Lee7A Cheung7A Wong7S Ho7S

9 Oct 2001 cylauFoxpro Chapter 99 Queries with Distinction SELECT DISTINCT house; FROM student;(Note the use of ‘;’) Faith Hope Love Wisdom (Note: the records are automatically sorted on house)

10 Oct 2001 cylauFoxpro Chapter 910 Order the Result of the Query zSELECT * FROM student Order by result ClassNoNameHouseResult 7A09CheungWisdom12.9 7S38WongHope13.1 7A01ChanLove13.3 7A15LeeFaith13.8 7S12HoFaith14.2

11 Oct 2001 cylauFoxpro Chapter 911 A Procedural Alternative USE student INDEX ON result TO student LIST z3 commands(one only for SQL) zstep by step is procedural (steps unknown in SQL) zKnow HOW to index, HOW to … (In SQL, give me WHAT is required)

12 Oct 2001 cylauFoxpro Chapter 912 Specifying alias for column SELECT name, house, result AS time; FROM student; ORDER BY time&& Not by result (key word AS can be omitted) NameHouseTime CheungWisdom12.9 WongHope13.1 ChanLove13.3 LeeFaith13.8 HoFaith14.2

13 Oct 2001 cylauFoxpro Chapter 913 Simple Expressions in Query zSELECT name, result old, result - 0.5 new; zFROM student ORDER BY new NameOldNew Cheung12.912.4 Wong13.112.6 Chan13.312.8 Lee13.813.3 Ho14.213.7

14 Oct 2001 cylauFoxpro Chapter 914 Revision on Functions P.286... Name is “Betty Au ”&& 1 space after Au zLen(name)9 zUPPER(name)BETTY AU zLOWER(name)betty au zLEFT(name,3)Bet zRIGHT(name,3)Au zALLTRIM(name)Betty Au zSUSTR(name, 1, at(‘ ‘,name)-1)Betty

15 Oct 2001 cylauFoxpro Chapter 915 Special Character Processing zSTR(123.456, 8, 2) 123.46 zVAL(‘5E2’) 5*10 2 500.00 zASC(‘A’)65 zCHR(97)‘a’ zLEN(‘ABC’)3

16 Oct 2001 cylauFoxpro Chapter 916 DateP.294 or P.56 Date is {09/11/2001} zDAY(date)11 zDOW(date)3 && Sunday=1st day zCDOW(date)Tuesday zMONTH(date)9 zCMONTH(date)September zYEAR(date)2001

17 Oct 2001 cylauFoxpro Chapter 917 Set Date, Century,... Date is {09/11/01} z?date09/11/1901 Set Century On 09/11/01Set Century Off z?CMONTH(date) ySeptemberdate is created after set date to American yNovemberdate is created after set date to British

18 Oct 2001 cylauFoxpro Chapter 918 Exercise Chapter 9, P. 299 z1, 2, 5 (Theory) z6, 7, 8(Warm Up) z10, 11, 12, 13, 14 TOO MUCH? Practice Makes Prefect Complete at least half before the next lesson


Download ppt "Oct 2001 cylauFoxpro Chapter 91 Chapter 9 SQL Structural Query Language."

Similar presentations


Ads by Google