Visual Basic
®6
Database
Visual Basic
®
6
Database
Programming Bible
Wayne S. Fre e ze
IDG Bo o ks Wo rldwide, Inc . An Internatio nal Data Gro up Co mpany
Visual Basic®6 Database Programming Bible rights reserved. No part o f this bo o k, inc luding interio r design, c o ver design, and ic o ns, may be repro duc ed o r transmitted in any fo rm, by any means (elec tro nic , pho to c o pying, rec o rding, o r o therwise)
Distributed by CDG Bo o ks Canada Inc . fo r Canada; by Transwo rld Publishers Limited in the United Kingdo m; by IDG No rge Bo o ks fo r No rway; by IDG Sweden Bo o ks fo r Sweden; by IDG Bo o ks Australia Publishing Co rpo ratio n Pty. Ltd. fo r Australia and New Zealand; by TransQuest Publishers Pte Ltd. fo r Singapo re, Malaysia, Thailand, Indo nesia, and Ho ng Ko ng; by Go to p Info rmatio n Inc . fo r Taiwan; by ICG Muse, Inc . fo r Japan; by Interso ft fo r So uth Afric a; by Eyro lles fo r Franc e; by Internatio nal Tho mso n Publishing fo r Germany, Austria, and Switzerland; by Distribuido ra Cuspide fo r Argentina; by LR Internatio nal fo r Brazil; by Galileo Libro s fo r Chile; by Edic io nes ZETA S.C.R. Ltda. fo r Peru; by WS
Fo r c o nsumer info rmatio n o n fo reign language translatio ns, please c o ntac t o ur Custo mer Servic e department at 800-434-3422, fax 317-572-4002, o r e-mail rights@idgbo o ks.c o m.
Fo r info rmatio n o n lic ensing fo reign o r do mestic rights, please pho ne +1-650-653-7098.
Fo r sales inquiries and spec ial pric es fo r bulk quant-ities, please c o ntac t o ur Order Servic es department Fo r press review c o pies, autho r interviews, o r o ther public ity info rmatio n, please c o ntac t o ur Public Relatio ns department at 650-653-7000 o r fax
LIMIT OF LIABILITY/ DISCLAIMER OF WARRANTY: THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS IN PREPARING THIS BOOK. THE PUBLISHER AND AUTHOR MAKE NO AND THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY INDIVIDUAL. NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES.
Trade marks:All brand names and pro duc t names used in this bo o k are trade names, servic e marks, trademarks, o r registered trademarks o f their respec tive o wners. IDG Bo o ks Wo rldwide is no t asso c iated with any pro duc t o r vendo r mentio ned in this bo o k.
Eleventh Annual
IDG is the world’s leading IT media, research and exposition company. Founded in 1964, IDG had 1997 revenues of $2.05 billion and has more than 9,000 employees worldwide. IDG offers the widest range of media options that reach IT buyers in 75 countries representing 95% of worldwide IT spending. IDG’s diverse product and services portfolio spans six key areas including print publishing, online publishing, expositions and conferences, market research, education and training, and global marketing services. More than 90 million people read one or more of IDG’s 290 magazines and newspapers, including IDG’s leading global brands — Computerworld, PC World, Network World, Macworld and the Channel World family of publications. IDG Books Worldwide is one of the fastest-growing computer book publishers in the world, with more than 700 titles in 36 languages. The “...For Dummies®” series alone has more than 50 million copies in print. IDG offers online
users the largest network of technology-specific Web sites around the world through IDG.net (http://www.idg.net), which comprises more than 225 targeted Web sites in 55 countries worldwide. International Data Corporation (IDC) is the world’s largest provider of information technology data, analysis and consulting, with research centers in over 41 countries and more than 400 research analysts worldwide. IDG World Expo is a leading producer of more than 168 globally branded conferences and expositions in 35 countries including E3 (Electronic Entertainment Expo), Macworld Expo, ComNet, Windows World Expo, ICE (Internet Commerce Expo), Agenda, DEMO, and Spotlight. IDG’s training subsidiary, ExecuTrain, is the world’s largest computer training company, with more than 230 locations worldwide and 785 training courses. IDG Marketing Services helps industry-leading IT companies build international brand recognition by developing global integrated marketing programs via IDG’s print, online and exposition products worldwide. Further information about the company can be found
at www.idg.com. 1/26/00
Welcome to the world of IDG Books Worldwide.
IDG Books Worldwide, Inc., is a subsidiary of International Data Group, the world’s largest publisher of computer-related information and the leading global provider of information services on information technology. IDG was founded more than 30 years ago by Patrick J. McGovern and now employs more than 9,000 people worldwide. IDG publishes more than 290 computer publications in over 75 countries. More than 90 million people read one or more IDG publications each month.
Launched in 1990, IDG Books Worldwide is today the #1 publisher of best-selling computer books in the United States. We are proud to have received eight awards from the Computer Press Association in recognition of editorial excellence and three from Computer Currents’ First Annual Readers’ Choice Awards. Our best-selling ...For Dummies® series has more than 50 million copies in print with translations in 31 languages. IDG
Books Worldwide, through a joint venture with IDG’s Hi-Tech Beijing, became the first U.S. publisher to publish a computer book in the People’s Republic of China. In record time, IDG Books Worldwide has become the first choice for millions of readers around the world who want to learn how to better manage their businesses.
Our mission is simple: Every one of our books is designed to bring extra value and skill-building instructions to the reader. Our books are written by experts who understand and care about our readers. The knowledge base of our editorial staff comes from years of experience in publishing, education, and journalism — experience we use to produce books to carry us into the new millennium. In short, we care about books, so we attract the best people. We devote special attention to details such as audience, interior design, use of icons, and illustrations. And because we use an efficient process of authoring, editing, and desktop publishing our books electronically, we can spend more time ensuring superior content and less time on the technicalities of making books.
You can count on our commitment to deliver high-quality books at competitive prices on topics you want to read about. At IDG Books Worldwide, we continue in the IDG tradition of delivering quality for more than 30 years. You’ll find no better book on a subject than one from IDG Books Worldwide.
Credits
written nine different bo o ks o n Visual Basic and SQL Server sinc e he began his c areer three years ago .He lives in Beltsville, Maryland, with his lo vely wife, Jill, and their wo nderful c hil-dren, Christo pher, age six, and Samantha, age five. Jill is a well-respec ted writer and Mic ro so ft beta tester, spec ializing in Mic ro so ft Offic e, Internet Explo rer, and Windo ws. Chris is perhaps the yo ungest perso n to beta test so ftware fo r Mic ro so ft, having tested bo th Windo ws 98 and Mic ro so ft Millennium, amo ng o ther pro duc ts, in his sho rt c areer. Sam, o n the o ther hand, lo ves to sit o n Wayne’s lap, and o ne day ho pes to write bo o ks just like her mo m and dad.
To gether, they live in a ho use full o f animals, inc luding a go lden retriever named Lady Ko ko mo and fo ur c ats named Pixel, Terry, Cali, and Dusty. Wayne also has a pet stingray named Raymo nd, after his father-in-law. Raymo nd lo ves to eat wo rms fro m Wayne’s hand (the stingray, that is, no t his father-in-law).
Preface
W
ith respec t to the develo pment o f database applic atio ns, Visual Basic is the language o f c ho ic e fo r pro grammers all o ver the wo rld. There are many rea-so ns they c ho o se Visual Basic : o ne, it is easy to learn ho w to use; two , yo u c an build c o mplex applic atio ns faster in Visual Basic than in any o ther pro gramming language; and three, Visual Basic pro grams are easy to debug. In additio n, there is a lo t o f spe-c ialized suppo rt built into Visual Basispe-c fo r develo ping database applispe-c atio ns. No t o nly c an yo u develo p traditio nal, fo rms-o riented database applic atio ns using Visual Basic , yo u c an also use it to develo p bac kend database pro grams fo r yo ur Web server that are far mo re effic ient than traditio nal PERL sc ripts o r Ac tive Server Pages.Mo st o f the Visual Basic bo o ks o n the market to day, ho wever, do wnplay these database aspec ts in favo r o f all o f the o ther neat features built into the language. While c alling API func tio ns fro m Visual Basic and develo ping Add-ins fo r the IDE c an be useful to pic s, I c o ver far mo re database-o riented material than yo u wo uld find in a typic al Visual Basic pro gramming bo o k by fo c using stric tly o n database pro gram-ming aspec ts. Yo u’ll benefit fro m the mo re fo c used c o verage, bec ause yo u’ll learn abo ut the database features that yo u need to kno w and whic h will make yo u a mo re pro duc tive database pro grammer.
Who Should Read This Book
If yo u read the bac k c o ver, yo u’ll find that this bo o k is aimed at beginning to
advanc ed readers. That’s quite a c hallenge. I do n’t want to bo re advanc ed pro gram-mers, who may want to learn tho se dirty tric ks that wo uld make their applic atio ns mo re effic ient, yet I do n’t want to lo se no vic e database pro grammers who c o uld benefit fro m tho se same tric ks.
I’m go ing to assume that everyo ne reading this bo o k is familiar with ho w to c reate and debug a Visual Basic pro gram — no t just the simple “Hello Wo rld” variety, but o ne that had so muc h c o de, fo r instanc e, it didn’t wo rk the first time yo u tried to c o mpile and run it. I’ll intro duc e yo u to any o ther info rmatio n yo u’ll need beyo nd this level.
x
Visual Basic 6 Database Programming BibleWhat This Book Covers
This bo o k is designed to be the o nly c o mbinatio n referenc e and tuto rial yo u will need fo r building Visual Basic database applic atio ns. To ac c o mplish that, this bo o k c o vers the fo llo wing database systems:
✦Mic ro so ft SQL Server 7 ✦Mic ro so ft Jet 3.51/ 4.0 ✦Orac le 8i
Bec ause muc h o f the material yo u need to kno w abo ut database pro gramming is c o mmo n to all three database servers, I have presented it first, in the fo llo wing list o f to pic s:
✦Database Pro gramming Fundamentals ✦Ac tiveX Data Objec ts (ADO)
✦Ac tiveX Data Objec t Extensio ns (ADOX) ✦Traditio nal c lient/ server applic atio ns ✦IIS Applic atio ns
✦Bo und c o ntro ls ✦Sto red pro c edures ✦COM+ Transac tio n Server ✦Mic ro so ft Message Queues ✦XML
Onc e I finish c o vering the c o mmo n material, I’ll fo c us o n eac h individual database server to give yo u the spec ific kno wledge yo u need to build effic ient database appli-c atio ns. Fo r eaappli-c h o f the database servers, I’ll appli-c o ver these to piappli-c s:
✦Database server to o ls and utilities ✦Useful SQL language extensio ns ✦ADO c o nsideratio ns
✦Unique data types and their Visual Basic equivalents ✦Sec urity mec hanisms
xi
Preface
The ac c o mpanying CD-ROM c o ntains all o f the sample pro grams fo und in this bo o k, plus a sample database that yo u c an use to test these pro grams. It’s my belief that the best way to learn pro gramming is to study as many pro grams as po ssible. Sinc e the c o mplete sample pro grams are o n disk, yo u c an lo ad them, try them o ut, and mo dify them to see ho w they wo rk, and ho pefully inc o rpo rate the same tec hniques into yo ur o wn applic atio ns.
What This Book Doesn’t Cover
This bo o k will no t teac h yo u the fundamentals o f Visual Basic pro gramming. If yo u do n’t kno w what a For Nextlo o p o r a Functionis, run to the nearest bo o ksto re and get a c o py o f Visual Basic 6 fo r Dummie sby Wallac e Wang. When yo u finish that bo o k and understand the material in it, yo u’ll be ready fo r this bo o k.
While this b o o k inc ludes a primer o n relatio nal datab ase c o nc epts and the SQL language, I suggest that yo u read SQL fo r Dummie sb y Allen G. Taylo r fo r a mo re in-depth c o verage o f SQL and relatio nal datab ases. Yo u may also want to c hec k o ut Micro so ft SQL Se rve r 7 fo r Dummie sb y Antho ny T. Mann and Oracle 8i fo r Dummie sb y Caro l Mc Cullo ugh fo r mo re info rmatio n ab o ut the spec ific datab ase servers c o vered in this b o o k.
Ano ther thing to c o nsider is that the emphasis in this bo o k is o n database pro gram-ming. While this is a fairly bro ad to pic , there are many things yo u might want to inc lude in yo ur pro grams that I might no t c o ver, suc h as ho w to c o nstruc t help files, ho w to use reso urc e files to so lve lo c alizatio n issues, and ho w to send e-mail mes-sages using MAPI. Yo u might c hec k o ut the Visual Basic 6 Bibleby Eric A. Smith, Valo r Whisler, and Hank Marquis, o r so me o f my o ther Visual Basic bo o ks. Yo u c an find a c o mplete list o f bo o ks that I have written at www.JustPC.com.
Hardware and Software Requirements
xii
Visual Basic 6 Database Programming BibleThe database server is also Gateway c o mputer with a Pentium 120 pro c esso r and 80MB o f main memo ry, running Windo ws 2000 Server. Obvio usly, SQL Server 7 and Orac le 8iwere installed, plus the Internet Info rmatio n Server (IIS), Mic ro so ft Message Queues, and COM+ Transac tio n Server. Just fo r fun, I also installed Offic e 2000 and Visual Basic 6 o n this mac hine. The two c o mputers were c o nnec ted using a 10 MHz Ethernet LAN. The c o mbinatio n was a lo t slo wer than I wo uld have liked, even after I spent a lo t o f time retuning the system fo r o ptimal perfo rmanc e.
Running a database server isn’t a trivial task, espec ially if yo u want to run it o n Windo ws 2000 Server. Windo ws 2000 needs a lo t o f memo ry in o rder to have an ac c eptable level o f perfo rmanc e. I rec o mmend a minimum o f 256MB o f memo ry fo r Windo ws 2000 Server, tho ugh yo u c o uld get by with 128MB o f memo ry if yo u wanted to run Windo ws NT 4 Server. If po ssible, yo u sho uld have a minimum o f a 400MHz Pentium pro c esso r, tho ugh yo u c o uld get by with less if yo ur server isn’t heavily lo aded.
While it’s po ssible to run yo ur database and Visual Basic o n o ne mac hine, yo u’ll be happier if yo u c an dedic ate o ne mac hine to SQL Server and use a sec o nd fo r yo ur pro gramming. If yo u do c ho o se to use a single mac hine, yo u sho uld have a lo t o f memo ry, espec ially if yo u are running Windo ws 2000 server. Yo u sho uld also try to invest in a dual pro c esso r system with relatively fast SCSI disk drives.
Visit M y Web Site
I maintain a Web site at http://www.JustPC.comwith additio nal info rmatio n abo ut the bo o ks that my wife and I have written. Eac h bo o k has its o wn Web page, o n whic h I answer frequently asked questio ns and po int yo u to o ther reso urc es yo u may find interesting. If yo u get a c hanc e to sto p by, please sign my guest bo o k to let me kno w yo u were there.
xiii
Preface
Acknowledgments
S
o metimes, being a writer c an be the pits. The ho urs are lo ng, the edito rs are demanding, and yo u never seem to have time fo r yo ur family and friends. Everyo ne believes that yo u wo rk a few ho urs eac h mo rning if yo u feel like it, and then have the rest o f the day to play. What a laugh! As I write this, my c hildren have been asleep fo r abo ut eight ho urs, and they’ll be getting up sho rtly to leave fo r sc ho o l. My wife has been asleep fo r a few ho urs no w, and the o nly o ne awake, beside myself, is my c at Pixel, who has walked ac ro ss my keybo ard three times while I’ve tried to write this paragraph. I wish she wo uld go to sleep, to o . On the o ther hand, writing is so me-times its o wn reward. I enjo y so lving pro blems and teac hing o thers ho w to do things. Writing allo ws me to do bo th, witho ut the day-to -day headac hes that arise as a man-ager in a large c o mputer c enter.So while the rest o f the wo rld believes that writing is o nly a part-time jo b, I’d like to ac kno wledge a few o ther peo ple who believe o therwise.
My agent, Laura Belt, really earns her c o mmissio ns. She do es her best to ensure that I have mo ney fo r the things that mo st writers do n’t have, like elec tric ity to run my c o mputer and a ro o f o ver my head. No w if I c o uld o nly affo rd so mething to eat.
My ac quisitio ns edito r, Jo hn Osbo rn, c hallenged me to do this pro jec t with an impo ssibly tight sc hedule, and in a weak mo ment, I agreed. Ho wever, befo re I had a c hanc e to really get started o n this bo o k, he left fo r greener pastures. I’m no w wo rk-ing with Greg Cro y, who has been keeprk-ing me bo th c hallenged and busy.
Shaun, Elwyn, Ric k, Ariane, Dr. Bo b, Vero nic a, Sc o tt, Randy, Vikki, Bo b K., and Ian, are but a few o f my friends that I haven’t seen in mo nths. I pro mise to c all real so o n. Really. Okay, maybe after I finish the next bo o k. That is, exc ept fo r Ric k. I may need to sto p by and pic k yo ur brain and yo ur c lo set.
Buc ky and Go o se, my wife’s parents. I do n’t think I c o uld ask fo r a better set o f in-laws. See y’all in a c o uple o f days fo r the big party.
xvi
Visual Basic 6 Database Programming BibleIf yo u read this bo o k c arefully, yo u will find o c c asio nal referenc es to Christo pher, Samantha, and Jill. Chris, who is six, kno ws mo re abo ut c o mputers than so me well-paid peo ple I used to wo rk with and has beta tested mo re so ftware o n his c o mputer than mo st adults I kno w. While Samantha is o nly five, she already wants her o wn lapto p c o mputer so she c an write bo o ks like her mo mmy and daddy.
Contents at a Glance
Prefac e . . . ix
Ac kno wledgments . . . xv
Part I: Database Programming Fundamentals . . . 1
Chapter 1: Basic Co nc epts . . . 3
Chapter 2: The Relatio nal Database Mo del . . . 19
Chapter 3: Designing a Relatio nal Database . . . 31
Chapter 4: SQL Statement Primer . . . 49
Chapter 5: Intro duc ing Visual Basic . . . 77
Chapter 6: Ac c essing Databases fro m Visual Basic . . . 89
Part II: Beginning Database Programming . . . 103
Chapter 7: Co deless Database Pro gramming . . . 105
Chapter 8: Mo re Abo ut Bo und Co ntro ls . . . 119
Chapter 9: Pro gramming with Data Enviro nments . . . 141
Chapter 10: Building Repo rts with the Mic ro so ft Data Repo rt Designer . . . 169
Part III: Hardcore ADO . . . 199
Chapter 11: The ADO Objec t Mo del . . . 201
Chapter 12: Co nnec ting to a database . . . 211
Chapter 13: Using Co mmands and Sto red Pro c edures . . . 235
Chapter 14: Wo rking with Rec o rdsets — Part I . . . 265
Chapter 15: Wo rking with Rec o rdsets — Part II . . . 299
Wo rking with Rec o rdsets — Part III . . . 327
Part IV: COM + Transactions and M essage Queues . . . 347
Chapter 17: Building Yo ur Own Bo und Co ntro ls . . . 349
Chapter 18: Using COM+ Transac tio ns . . . 369
Chapter 19: Using Message Queues . . . 399
Part V: The Impact of XM L . . . 431
Chapter 20: Intro duc ing XML . . . 433
Chapter 21: The Do c ument Objec t Mo del . . . 455
xviii
Visual Basic 6 Database Programming BiblePart VI: SQL Server . . . 505
Chapter 23: Overview o f SQL Server . . . 507
Chapter 24: Creating Database Objec ts with SQL Server . . . 523
Chapter 25: Creating Sto red Pro c edures with SQL Server . . . 557
Part VII: Oracle 8i . . . 579
Chapter 26: Overview o f Orac le8i . . . 581
Chapter 27: Creating Database Objec ts with Orac le8i . . . 599
Chapter 28: Creating Sto red Pro c edures with Orac le8i . . . 627
Part VIII: M icrosoft Jet . . . 647
Chapter 29: Overview o f Mic ro so ft Jet . . . 649
Chapter 30: Creating Database Objec ts with Mic ro so ft Jet . . . 663
Appendix: CD-ROM Installatio n Instruc tio ns . . . 679
Index . . . 709
End Users Lic ense . . . 729
Contents
Preface. . . ix
Acknow ledgm ents . . . xv
Part I: Database Programming Fundamentals
1
Chapter 1: Basic Concepts . . . 3
Why Use a Database? . . . 3
Sto ring info rmatio n . . . 3
Co nc urrenc y . . . 5
Sec uring yo ur data . . . 6
Perfo rming bac kups and using transac tio n lo gs . . . 6
A database is the answer . . . 7
Database Arc hitec ture . . . 8
Servers and c lients . . . 8
Database servers and database c lients . . . 9
Types o f Databases . . . 11
Hierarc hic al databases . . . 11
Netwo rked databases . . . 11
Indexed databases . . . 13
Relatio nal databases . . . 13
Co mmo n Databases . . . 14
SQL Server 7.0 . . . 14
Mic ro so ft Jet 3.5/ 4.0 . . . 15
Orac le 8i . . . 15
Chapter 2: The Relational Database M odel . . . 19
Intro duc ing the Struc tured Query Language . . . 19
Relatio nal histo ry . . . 19
Business benefits o f a relatio nal database . . . 23
Parts o f a Relatio nal Database . . . 24
Tables and ro ws o f data . . . 24
Co lumns and data types . . . 24
Indexes and keys . . . 25
Views . . . 27
xxiii
Contents
Data Enviro nment RunTime Objec t Mo del . . . 161
DataEnviro nment pro perties . . . 161
DataEnviro nment metho ds . . . 162
Data Enviro nment events . . . 163
Viewing Databases with the Data View Windo w . . . 163
Co nfiguring the Data View Windo w . . . 164
Wo rking with database diagrams . . . 164
Wo rking with tables . . . 165
Wo rking with views . . . 166
Wo rking with sto red pro c edures . . . 167
Chapter 10: Building Reports with the M icrosoft Data
Report Designer . . . 169
Intro duc ing the Mic ro so ft Data Repo rt . . . 169
Using the Data Repo rt Designer . . . 170
Getting yo ur data . . . 170
Building a data repo rt’s struc ture . . . 170
Plac ing c o ntro ls o n yo ur repo rt . . . 172
Pro gramming Yo ur Repo rt . . . 176
Previewing a repo rt . . . 176
Printing a Repo rt . . . 177
Expo rting repo rts . . . 178
Trac king async hro no us ac tivity . . . 179
The Data Repo rt o bjec t mo del . . . 179
DataRepo rt pro perties . . . 179
DataRepo rt metho ds . . . 181
Key DataRepo rt events . . . 182
Co ntro ls c o llec tio n pro perties . . . 184
Expo rtFo rmat o bjec t pro perties . . . 184
Expo rtFo rmats c o llec tio n pro perties . . . 184
Expo rtFo rmats c o llec tio n metho ds . . . 185
RptErro r o bjec t pro perties . . . 187
RptFunc tio n c o ntro l pro perties . . . 187
RptImage c o ntro l pro perties . . . 189
RptLabel c o ntro l pro perties . . . 190
RptLine c o ntro l pro perties . . . 192
RptShape c o ntro l pro perties . . . 193
RptTextBo x c o ntro l pro perties . . . 194
Sec tio n o bjec t pro perties . . . 195
xxx
Visual Basic 6 Database Programming BibleDatabase Arc hitec ture . . . 512
System databases . . . 512
SQL Server data types . . . 516
Co nnec ting to SQL Server with ADO . . . 518
SQL Server Sec urity . . . 518
Authentic atio n in SQL Server . . . 518
SQL Server autho rizatio n . . . 520
SQL Server ro les . . . 520
Chapter 24: Creating Database Objects with SQL Server . . . 523
Intro duc ing Enterprise Manager . . . 523
Enterprise Manager fundamentals . . . 524
Registering a database server . . . 525
Viewing database servers and their o bjec ts . . . 527
Bro wsing data . . . 530
Databases and Tables . . . 531
Creating a database . . . 532
Creating a table . . . 535
Indexes and Diagrams . . . 539
Creating an index . . . 540
Creating a database diagram . . . 547
Managing Sec urity . . . 550
Creating a lo gin . . . 550
Granting permissio ns in a database . . . 553
Chapter 25: Creating Stored Procedures with SQL Server . . . 557
Intro duc ing Sto red Pro c edures . . . 557
Why use sto red pro c edures? . . . 557
Intro duc ing Transac t-SQL . . . 559
Co mments . . . 559
Identifiers . . . 560
Variables . . . 561
Func tio ns . . . 561
Expressio ns . . . 563
Flo w c o ntro l . . . 563
Curso rs . . . 565
Pro c essing transac tio ns . . . 570
Other useful statements . . . 571
Creating and Testing Sto red Pro c edures . . . 573
Creating sto red pro c edures in SQL Server . . . 574
xxxi
Contents
Part VII: Oracle 8i
579
Chapter 26: Overview of Oracle8i . . . 581
Overview . . . 581
Orac le8i editio ns . . . 582
Orac le8i utilities . . . 583
Understanding the Database Arc hitec ture . . . 586
Key database o bjec ts . . . 587
Memo ry arc hitec ture . . . 589
Netwo rk arc hitec ture . . . 590
Orac le8i data types . . . 590
Co nnec ting to Orac le8i . . . 591
Orac le8i Sec urity . . . 593
Authentic atio n . . . 593
Autho rizatio n . . . 593
Ro les . . . 596
Chapter 27: Creating Database Objects with Oracle8i . . . 599
Intro duc ing SQL*Plus . . . 599
Co mmand-Line SQL*Plus . . . 599
Co nnec ting to yo ur database with SQL*Plus . . . 600
Entering c o mmands . . . 601
Useful c o mmands . . . 601
Intro duc ing Enterprise Manager . . . 603
The Enterprise Manager c o nso le . . . 604
SQL*Plus Wo rksheet . . . 607
DBA Studio . . . 610
Creating Tablespac es . . . 612
Befo re yo u c reate a tablespac e . . . 612
Creating yo ur tablespac e . . . 613
Creating Tables and Indexes . . . 614
Creating yo ur table . . . 615
Mo difying a table . . . 619
Creating an index . . . 621
Managing Sec urity . . . 621
Creating ro les . . . 621
Creating users . . . 622
xxxii
Visual Basic 6 Database Programming BibleChapter 28: Creating Stored Procedures with Oracle8i . . . 627
Intro duc ing PL/ SQL . . . 627
Co mments . . . 627
Co nstants . . . 628
Identifiers . . . 628
Variables . . . 628
Func tio ns . . . 629
Blo c k struc ture . . . 630
Pro c edures, func tio ns, and pac kages . . . 633
Expressio ns . . . 634
Flo w c o ntro l . . . 635
Curso rs . . . 637
Transac tio ns . . . 641
Other useful statements . . . 642
Creating Sto red Pro c edures . . . 643
Creating a pro c edure o r func tio n . . . 644
Creating a pac kage . . . 644
Part VIII: M icrosoft Jet
647
Chapter 29: Overview of M icrosoft Jet . . . 649
Overview o f Jet . . . 649
Mic ro so ft Jet versio ns . . . 650
Jet and DAO . . . 651
Jet utilities . . . 652
Understanding the Database Arc hitec ture . . . 652
.MDB files . . . 652
.LDB files . . . 653
.MDW Files . . . 653
Database o bjec ts . . . 654
Linked databases . . . 654
Database c apac ities . . . 655
Jet data types . . . 655
Co nnec ting to Jet with ADO . . . 655
Jet sec urity . . . 658
Share-level sec urity . . . 658
User-level sec urity . . . 659
Chapter 30: Creating Database Objects with M icrosoft Jet . . . 663
Intro duc ing the Visual Data Manager . . . 663
Opening an existing database . . . 664
Viewing Database Info rmatio n . . . 665
xxxiii
Contents
Co nstruc ting Databases, Tables, and Indexes . . . 669
Creating a new database . . . 669
Creating a table . . . 670
Creating an index . . . 672
Using the DAO and ADOX alternatives . . . 673
Managing Sec urity . . . 673
The sec urity definitio n file . . . 673
Managing users and gro ups . . . 673
Managing permissio ns and o wnership . . . 676