- Page 2:
Beginning SQL Paul Wilton and John
- Page 10:
Beginning SQL Paul Wilton and John
- Page 14:
About the Authors Paul Wilton After
- Page 18:
Paul Wilton: With lots of love to m
- Page 24:
Contents x Selecting Correct Data T
- Page 28:
Contents xii Re-examining NULL 180
- Page 32:
Contents Chapter 11: Transactions 3
- Page 36:
Contents xvi How Do You Do It? 357
- Page 42:
Introduction Data, data, data! Data
- Page 46:
By the time you’ve completed Chap
- Page 50:
Once you download the code, just de
- Page 54:
1 Introduction to SQL A nice, gentl
- Page 58:
Figure 1-1 Why and When to Use a Da
- Page 62:
Databases are great at dealing with
- Page 66:
The SQL language is actually fairly
- Page 70:
you wish, and the database system d
- Page 74:
A keyword is a word that has some m
- Page 78:
Introduction to SQL A perfectly val
- Page 82:
Data Type Description Storage Used
- Page 86:
The char and varchar data types use
- Page 90:
Most RDBMSs handle the most common
- Page 94:
To add a new column, use the basic
- Page 98:
Now that you know what you want to
- Page 102: ❑ Meeting date 2 ❑ Location 2
- Page 106: Generally speaking, picking a data
- Page 110: example, the MemberId field links t
- Page 114: Depending on which RDBMS you’re u
- Page 118: The FilmCategory table is very smal
- Page 122: 2 Entering Information The last cha
- Page 126: like this: INSERT INTO Category VAL
- Page 130: Inserting Data into the Case Study
- Page 134: The WHERE Clause So far you’ve se
- Page 138: Try It Out Using Logical Operators
- Page 142: Exercises 1. Three new members have
- Page 148: Chapter 3 54 MemberId FirstName 1 K
- Page 152: Chapter 3 The results are as follow
- Page 158: MemberDetails (MemberId, FirstName,
- Page 162: MemberDetails table, the columns Fi
- Page 166: State DateOfJoining New State 2005-
- Page 170: It simply tells the database system
- Page 174: The BETWEEN operator functions exac
- Page 178: The final condition required is a c
- Page 182: In some database systems, the LIKE
- Page 186: The second query is a negative, in
- Page 190: Because both conditions (YearReleas
- Page 194: YearReleased 1984 1980 1977 1975 19
- Page 198: First, the database system orders t
- Page 202: LastName FirstName DateOfBirth Nigh
- Page 206:
The preceding SQL returns the follo
- Page 210:
If you put square brackets around i
- Page 214:
Finally, if you want to use an alia
- Page 218:
Member Name The member is called Ka
- Page 222:
FilmName YearReleased Rating Sense
- Page 226:
Figure 3-1 The first task when tack
- Page 230:
That’s all well and good, but so
- Page 234:
Category FirstName LastName War Jen
- Page 238:
Extracting Information FirstName La
- Page 242:
If you take this further and join t
- Page 246:
SELECT * FROM FavCategory Figure 3-
- Page 250:
Category MemberId Thriller 5 Thrill
- Page 254:
Remember to add brackets around the
- Page 258:
surprisingly, the MemberDetails tab
- Page 262:
LocationId 2 2 2 2 1 1 1 Figure 3-6
- Page 266:
includes that record. You should al
- Page 270:
FirstName LastName DateOfBirth Jenn
- Page 274:
4 Advanced Database Design This cha
- Page 278:
Date of Date Meeting Did Member Nam
- Page 282:
Now the tables are in second normal
- Page 286:
After changing the database so that
- Page 290:
IBM’s DB2 doesn’t allow you to
- Page 294:
The following code creates a new ta
- Page 298:
If you’re using DB2, the code is
- Page 302:
The NOT NULL constraint prevents th
- Page 306:
In the preceding code, CustomerId i
- Page 310:
Foreign Key Foreign keys are column
- Page 314:
MemberId MeetingDate Street City St
- Page 318:
The third step had you create the p
- Page 322:
The results are ordered because, by
- Page 326:
The index is no longer needed, so d
- Page 330:
WHERE MemberAttended = ‘Y’; DRO
- Page 334:
Primary keys must be unique and can
- Page 338:
Then add the PRIMARY KEY constraint
- Page 342:
( ); FilmId integer NOT NULL, FilmN
- Page 346:
ALTER TABLE Attendance ADD CONSTRAI
- Page 350:
❑ You learned the importance of e
- Page 356:
Chapter 5 158 Function Operator Mul
- Page 360:
Chapter 5 Consider the following SQ
- Page 364:
Chapter 5 The SQRT() Function The S
- Page 368:
Chapter 5 164 chairperson now also
- Page 372:
Chapter 5 The FLOOR() Function The
- Page 376:
Chapter 5 DVDPrice ROUND(DVDPrice,1
- Page 380:
Chapter 5 Note that, as with all th
- Page 384:
Chapter 5 The TRIM() Functions Trim
- Page 388:
Chapter 5 174 In Oracle and IBM’s
- Page 392:
Chapter 5 176 FirstName SOUNDEX(Fir
- Page 396:
Chapter 5 Date Functions 178 Someti
- Page 400:
Chapter 5 The syntax for the CAST()
- Page 404:
Chapter 5 NULLs and Strings 182 NUL
- Page 408:
Chapter 5 184 SELECT FirstName, Las
- Page 412:
Chapter 5 186 This SQL copies over
- Page 416:
Chapter 5 You also learned that mat
- Page 420:
Chapter 6 190 Begin by looking at h
- Page 424:
Chapter 6 This section covers queri
- Page 428:
Chapter 6 194 This query gives the
- Page 432:
Chapter 6 You’re almost there. Yo
- Page 436:
Chapter 6 the database even though
- Page 440:
Chapter 6 SELECT Category, AVG(DVDP
- Page 444:
Chapter 6 Try It Out Selecting Data
- Page 448:
Chapter 6 SELECT Category, COUNT(Fa
- Page 454:
7 Selecting Data from Different Tab
- Page 458:
Selecting Data from Different Table
- Page 462:
Note that MS Access insists that yo
- Page 466:
City State Orange Town New State Wi
- Page 470:
SELECT FM1.FilmName FROM Films AS F
- Page 474:
Selecting Data from Different Table
- Page 478:
effects of any WHERE clause. There
- Page 482:
Now re-execute the query. You get a
- Page 486:
the category list and a list of whi
- Page 490:
Category FirstName LastName Horror
- Page 494:
You can join the results from two o
- Page 498:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
- Page 502:
function and the query still works,
- Page 506:
Summary Selecting Data from Differe
- Page 512:
Chapter 8 A WHERE clause is added t
- Page 516:
Chapter 8 238 FilmName PlotSummary
- Page 520:
Chapter 8 If you think that your jo
- Page 524:
Chapter 8 In the query, the Categor
- Page 528:
Chapter 8 244 There is one area in
- Page 532:
Chapter 8 246 SELECT FirstName, Las
- Page 536:
Chapter 8 248 The subquery (SELECT
- Page 540:
Chapter 8 250 Notice the use of the
- Page 544:
Chapter 8 4. You should receive the
- Page 548:
Chapter 8 254 This inner query retu
- Page 552:
Chapter 8 It’s quite important no
- Page 556:
Chapter 8 258 To tackle this query,
- Page 560:
Chapter 8 260 Now you need to find
- Page 566:
9 Advanced Queries In database prog
- Page 570:
FOREIGN KEY (OrderId) REFERENCES Or
- Page 574:
INSERT INTO Orders(OrderId, MemberI
- Page 578:
INSERT INTO OrderItems(OrderId,Film
- Page 582:
A more complex question could be,
- Page 586:
Advanced Queries What you really wa
- Page 590:
FirstName and LastName. You need to
- Page 594:
2. The film club chairperson also w
- Page 598:
Executing the preceding query provi
- Page 602:
GROUP BY SalesPerson.SalesPersonId,
- Page 606:
Executing the preceding SQL creates
- Page 610:
❑ Use IN with your subqueries. Wh
- Page 614:
10 Views Views, as the name implies
- Page 618:
Try It Out Building a View 1. The p
- Page 622:
FROM dbo.MemberDetails INNER JOIN d
- Page 626:
For example, you might want a list
- Page 630:
However, if you take the case of Me
- Page 634:
However, someone writes a query tha
- Page 638:
Summary As you learned, views are l
- Page 644:
Chapter 11 The information that fol
- Page 648:
Chapter 11 This SQL adds formats (d
- Page 652:
Chapter 11 TRANSACTION statement is
- Page 656:
Chapter 11 Additionally, if a DBMS
- Page 660:
Chapter 11 ROLLBACK TRANSACTION 310
- Page 664:
Chapter 11 Transaction Logs 312 How
- Page 668:
Chapter 11 Database There are perfe
- Page 672:
Chapter 11 In order to find and fix
- Page 676:
Chapter 11 When discussing locking,
- Page 680:
Chapter 11 Usually, the default iso
- Page 684:
Chapter 11 From Sue’s perspective
- Page 688:
Chapter 11 5. At this point, you ne
- Page 694:
12 SQL Security In today’s world,
- Page 698:
Setting up security begins with cre
- Page 702:
ALTER USER username options ALTER U
- Page 706:
In Figure 12-3, three different gro
- Page 710:
How It Works After you run this sta
- Page 714:
check constraints can be used in a
- Page 718:
You could then give SELECT privileg
- Page 722:
Limitations on Views Views are by t
- Page 726:
GRANT SELECT (NAME, SSN, SALARY) ON
- Page 730:
Betsey also grants privileges to Ji
- Page 734:
The CASCADE option tells the DBMS t
- Page 738:
13 Database Tuning SQL is a languag
- Page 742:
Perhaps this doesn’t sound remote
- Page 746:
When an application asks for data f
- Page 750:
The point of all the discussion of
- Page 754:
How Do You Do It? And herein lies t
- Page 758:
The slots are often implemented as
- Page 762:
On the other hand, an index on a tr
- Page 766:
Tuning Tips The following list cont
- Page 770:
Database Tuning Exercises 1. Create
- Page 776:
Appendix A Exercise 2 Solution 368
- Page 780:
Appendix A ( 8, ‘Jack’, ‘John
- Page 784:
Appendix A ZipCode, Email, DateOfJo
- Page 788:
Appendix A Exercise 3 Solution Firs
- Page 792:
Appendix A 376 Figure A-1 ISBN is a
- Page 796:
Appendix A Chapter 5 Exercise 1 Sol
- Page 800:
Appendix A 380 You might receive sl
- Page 804:
Appendix A 382 You should use the f
- Page 808:
Appendix A Your answer may differ,
- Page 812:
Appendix A WHERE (SELECT COUNT(*) f
- Page 816:
Appendix A Exercise 2 Solution CREA
- Page 820:
Appendix A Chapter 13 Exercise 1 So
- Page 824:
Appendix B 392 Click the database i
- Page 828:
Appendix B 394 Click Install to beg
- Page 832:
Appendix B 396 Select the Detailed
- Page 836:
Appendix B 398 Leave it at the defa
- Page 840:
Appendix B 400 Having entered your
- Page 844:
Appendix B 402 Figure B-20 The inst
- Page 848:
Appendix B 404 At the very top of t
- Page 852:
Appendix B 406 Having done that, ma
- Page 856:
Appendix B 408 Figure B-30 MyTable
- Page 860:
Appendix B 410 Figure B-32 Click Ne
- Page 864:
Appendix B 412 Click Next to contin
- Page 868:
Appendix B 414 Click OK to clear th
- Page 872:
Appendix B If you’re ready and ha
- Page 876:
Appendix B 418 You can also enter a
- Page 880:
Appendix B 420 Figure B-49 The Film
- Page 884:
Appendix B 422 Now you need to inse
- Page 888:
Appendix B 424 In Access it’s not
- Page 892:
Appendix B 426 Figure B-56 You need
- Page 896:
Appendix B 428 Then click the Run i
- Page 900:
Appendix B 430 The next screen (see
- Page 904:
Appendix B 432 On the next screen,
- Page 908:
Appendix B 434 Click Next to procee
- Page 912:
Appendix B 436 Figure B-72 The huge
- Page 916:
Appendix B 438 Figure B-74 Notice t
- Page 920:
Appendix B 440 Figure B-76 The Obje
- Page 924:
Appendix B 442 Figure B-78 Chapter
- Page 928:
Appendix B You don’t need MyTable
- Page 932:
Appendix B 446 Figure B-82 To begin
- Page 936:
Appendix B Using Oracle’s SQL*Plu
- Page 940:
Appendix B 450 Figure B-87 Another
- Page 944:
Appendix C Category Table The follo
- Page 948:
Appendix C 454 ( 3, ‘Sandra’,
- Page 952:
Appendix C 456 ZipCode, Email, Date
- Page 956:
Appendix C DateOfJoining ) VALUES (
- Page 960:
Appendix C 460 VALUES ( 1, 3 ); INS
- Page 964:
Appendix C VALUES ( 5, 3 ); INSERT
- Page 968:
Appendix C 464 3 ); INSERT INTO Fil
- Page 972:
Appendix C 5, 6 ); INSERT INTO Film
- Page 976:
Appendix C 468 5 ); INSERT INTO Att
- Page 980:
Appendix C Oracle 470 To save some
- Page 984:
Appendix C 472 LocationId, MeetingD
- Page 990:
Symbols + (addition operator), 82,
- Page 994:
BEGIN TRANSACTION statement, 306, 3
- Page 998:
SERIALIZABLE statement, 318 SET TRA
- Page 1002:
data types brackets, 25 categories,
- Page 1006:
Oracle concatenation, 85-88 configu
- Page 1010:
error messages debugging, 26 subque
- Page 1014:
concatenation, 85-88 data type comp
- Page 1018:
primary keys database creation exam
- Page 1022:
concurrent connection selection, 39
- Page 1026:
passwords group access, 333 IBM ins
- Page 1030:
ROLLBACK statement, 307-308 ROLLBAC
- Page 1034:
REPEATABLE READ, 319 REVOKE, 344-34
- Page 1038:
telephone numbers, data type select
- Page 1042:
historical, data selection, 90-94 N