Relational Databases: Design, Implementation, and Application ...

7 downloads 177451 Views 40KB Size Report
This book uses Microsoft Access 2010, a mid-range RDBMS, to teach ... design, development, maintenance, and application development. The book has been ...
Relational Databases: Design, Implementation, and Application Development

Amir Manzoor

Relational Databases: Design, Implementation, and Application Development

Copyright © 2012 by Amir Manzoor No part of this book shall be reproduced, stored in retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior written permission form the author. No patent liability is assumed with respect to the use of the information contained herein. While every precaution has been taken in the preparation of this book, the publisher and authors assumes no responsibility for errors and omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein. All inquiries should be addressed to the author. Relational Databases: Design, Implementation, and Application Development First Edition 2012 ISBN-13: 978-1479356973 ISBN-10: 1479356972 All rights reserved under the copyright act. Printed in the United States of America Trademark Acknowledgements Full acknowledgement is given of all proprietary trademarks and registered trademarks that are mentioned in this book. In addition, terms suspected of being trademarks or series marks have been appropriately capitalized, author cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. iii

Amir Manzoor

iv

DEDICATION To Samina, Shazil, and Aashir

vi

Relational Databases: Design, Implementation, and Application Development

ABOUT THE AUTHOR Amir Manzoor holds a bachelor’s degree in engineering from NED University, Karachi and an MBA from Lahore University of Management Sciences (LUMS). He also holds more than 12 international IT industry certifications such as MCSE, MCDBA, CCNA, CCDA, CSA, CCA, A+ etc. He is an Associate of Institute of Bankers, Pakistan and Certified Supply Chain Management Professional from NPO, Pakistan. He has served at senior technical consulting position in USA and Pakistan for many years. He is currently serving as Assistant Professor at management sciences department of Bahria University, Karachi. His research interests include electronic business and business use of information technology for competitive advantage.

vii

Amir Manzoor

viii

PREFACE In today's information age, databases have become primary tools for information organization and retrieval. Almost every organization, whether small or large, is dependent on use of databases. Among various types of databases, relational databases dominate because of their simplicity and ease of use. A relational database management system (RDBMS) is a tool used to manage a relational database. This book uses Microsoft Access 2010, a mid-range RDBMS, to teach the fundamentals of relational databases design, development, maintenance, and application development. The book has been written in simple language and focused and succinct manner. The book uses a visual approach avoiding lengthy text. This approach allows readers to efficiently utilize their reading time and master the material provided in minimum possible time. The readers will learn to create and link various database elements such as forms, queries, reports, and macros. This book is useful for undergrad and graduate students, professionals, and anyone looking to gain a solid foundation to continue their learning of relational databases. Amir Manzoor

ix

Amir Manzoor

x

Relational Databases: Design, Implementation, and Application Development

ACKNOWLEDGEMENTS It is not possible for me to list everyone who assisted in the preparation of this book. I thank and am very grateful for the teachers, students and all individuals who provided their valuable suggestions, feedback, and help during the preparation of this book.

xi

Amir Manzoor

xii

CONTENTS DEDICATION ....................................................................................................... V ABOUT THE AUTHOR........................................................................................ VII PREFACE ............................................................................................................ IX ACKNOWLEDGEMENTS ..................................................................................... XI CHAPTER 1

INTRODUCTION TO RELATIONAL DATABASES .........................19

DATABASE ........................................................................................................19 DATA AND INFORMATION .....................................................................................19 TABLE, RECORD, AND FIELDS .................................................................................20 RELATIONAL DATABASE .......................................................................................20 DATABASE CHOICES ............................................................................................21 MICROSOFT ACCESS ...........................................................................................21 DESIGNING AND DOCUMENTING YOUR DATABASE......................................................21 Database Design .......................................................................................22 CHAPTER 2

INTRODUCTION TO ACCESS 2010 ............................................31

MICROSOFT ACCESS 2010 – INTERFACE ..................................................................31 MICROSOFT ACCESS 2010 – FILE MENU .................................................................33 Open a Database.......................................................................................33 Closing a Database ....................................................................................33 Save a Database File..................................................................................33 Create a New Database .............................................................................34 Open an Existing Database ........................................................................34 ACCESS 2010 – DATABASE WINDOWS ....................................................................35 ACCESS 2010 - DATABASE VIEWS .........................................................................36 NAVIGATING FIELDS AND RECORDS .........................................................................37 TABLES ............................................................................................................38 To Copy Content Within or Between Tables................................................39 Tables in Access 2010 ................................................................................40 WORKING WITH TABLES.......................................................................................40 To Open an Existing Table..........................................................................40 To Change the View of a Table, Query, or Report .......................................40 To Delete a Table.......................................................................................41 13

Amir Manzoor

To Change the Width of a Column in the Table .......................................... 41 To Apply the Data Filter to a Table ............................................................ 42 To Add Fields to the Existing Table ............................................................ 42 To Change Order of Fields ......................................................................... 43 To Hide a Table ......................................................................................... 43 Validation Rules ........................................................................................ 44 RELATIONSHIPS ................................................................................................. 46 Benefits of Using Relationships ................................................................. 46 Referential Integrity Rules ......................................................................... 46 Setting Relationships ................................................................................ 47 Basic Types of Relationships ...................................................................... 50 JOINS ............................................................................................................. 51 CREATING DATABASE OBJECTS USING CREATE TAB .................................................... 52 QUERIES ......................................................................................................... 52 FORMS ........................................................................................................... 53 Types of Forms.......................................................................................... 54 EPORTS R ......................................................................................................... 54 Parts of a Report....................................................................................... 55 Creating a New Report.............................................................................. 56 Preview and Print a Report........................................................................ 57 Report Formats......................................................................................... 57 Add Report or Page Header and Footer Sections........................................ 58 Remove Report or Page Header and Footer Sections ................................. 58 Guideline to Designing Better Reports ....................................................... 58 EXPORTING DATABASE OBJECTS USING EXTERNAL DATA TAB ....................................... 58 THE STRUCTURE OF ACCESS DATABASE- LINKING DATABASE OBJECTS TOGETHER .............. 59 ANALYZING DATABASE OBJECTS DEPENDENCIES ........................................................ 60 CHAPTER 3 THE INVENTORY MANAGEMENT AND CONTROL SYSTEM (IMCS) ......................................................................................................................... 63 DEVELOPING INVENTORY MANAGEMENT AND CONTROL SYSTEM (IMCS) DATABASE ......... 63 APPLYING DATABASE DESIGN RULES ON IMCS DATABASE ........................................... 65 Rule 1: Organize your Data ....................................................................... 65 Rule 2: No Derived fields should be Used .................................................. 69 Rule 3: Data should be Broken Down into Smallest Logical Parts ............... 69 Rule 4: Descriptive Field Names Should Be Used ........................................ 69 Rule 5: Unique Field Names Should Be Used ............................................. 69 Rule 6: No Calculated Fields Should Be Used .............................................. 69 14

Relational Databases: Design, Implementation, and Application Development

Rule 7: Unique Records Should Be Used .....................................................69 IMCS TABLES AND THEIR DETAILS ..........................................................................70 CHAPTER 4

DEVELOPING TABLES ...............................................................73

CREATING A NEW TABLE ......................................................................................73 SET OR MODIFY THE PRIMARY KEY OF THE TABLE .......................................................75 SET A TABLE'S PROPERTIES ...................................................................................76 ADD A FIELD TO A TABLE ......................................................................................77 Add a Field by Entering Data......................................................................77 CREATE OR OPEN A TABLE IN DATASHEET VIEW .........................................................78 SET FIELD PROPERTIES .........................................................................................78 Set Field Properties in Datasheet view........................................................78 Set Field Properties in Design view .............................................................80 SAVE THE TABLE ................................................................................................84 SETTING INPUT MASK PROPERTY ...........................................................................84 TABLES OF INVENTORY MANAGEMENT AND CONTROL SYSTEM (IMCS) DATABASE .............86 CHAPTER 5

DEVELOPING RELATIONSHIPS................................................107

CREATE A TABLE RELATIONSHIP BY USING THE RELATIONSHIPS WINDOW ....................... 107 DELETE A TABLE RELATIONSHIP ............................................................................ 108 MODIFY A TABLE RELATIONSHIP .......................................................................... 109 MODIFY A TABLE JOIN ....................................................................................... 110 ENABLE OR DISABLE REFERENTIAL INTEGRITY OPTION................................................ 110 CREATING RELATIONSHIPS FOR INVENTORY MANAGEMENT AND CONTROL SYSTEM (IMCS)110 CHAPTER 6

DEVELOPING FORMS I ...........................................................115

FORM VIEWS .................................................................................................. 115 CREATE A FORM BY USING THE FORM TOOL ............................................................ 116 CREATE A FORM BY USING THE FORM WIZARD ........................................................ 116 CREATE A FORM BY USING THE BLANK FORM TOOL ................................................... 117 ADDING A CONTROL TO A FORM .......................................................................... 118 CREATING A SUBFORM ...................................................................................... 118 CREATING FORMS FOR INVENTORY MANAGEMENT AND CONTROL SYSTEM (IMCS) .......... 119 Categories Form ...................................................................................... 119 Employees Form ...................................................................................... 121 Company Information Form ..................................................................... 124 Report Data Range Form ......................................................................... 130 15

Amir Manzoor

Reports Form .......................................................................................... 133 Shipping Methods Form .......................................................................... 136 Suppliers Form ........................................................................................ 138 CHAPTER 7

DEVELOPING MACROS.......................................................... 145

INTRODUCTION ............................................................................................... 145 CREATING A MACRO ........................................................................................ 145 USING A MACRO ............................................................................................. 149 CREATING MACROS FOR INVENTORY MANAGEMENT AND CONTROL SYSTEM (IMCS) ....... 149 View Reports Macro................................................................................ 149 Products Macro ...................................................................................... 153 Purchase Orders Macro........................................................................... 158 CHAPTER 8

DEVELOPING FORMS II ......................................................... 163

PRODUCTS SUBFORM ....................................................................................... 163 PRODUCTS FORM ............................................................................................ 179 PURCHASE ORDERS SUBFORM ............................................................................ 193 PURCHASE ORDERS FORM ................................................................................. 198 VIEW REPORTS FORM ....................................................................................... 209 CHAPTER 9

DEVELOPING QUERIES .......................................................... 215

QUERIES IN ACCESS .......................................................................................... 215 CREATING A QUERY.......................................................................................... 215 Creating a Simple Query Using the Query Wizard .................................... 216 Creating a Crosstab Query ...................................................................... 219 Creating a Find Duplicates Query ............................................................ 223 Creating a Find Unmatched Query .......................................................... 226 CREATE A SIMPLE QUERY FOR IMCS USING DESIGN WIZARD...................................... 230 CREATING A SIMPLE QUERY BY DESIGN FOR IMCS ................................................... 233 CHAPTER 10

DEVELOPING REPORTS ....................................................... 237

DEVELOPING REPORTS FOR IMCS........................................................................ 237 Product Cost Comparisons Report ........................................................... 237 Product Purchases by Supplier Report ..................................................... 241 Product Summary Report ........................................................................ 244 Product Transaction Detail Report........................................................... 246 Purchase Order Report............................................................................ 248 EXPORT YOUR REPORT INTO OTHER FORMATS ........................................................ 254

16

Relational Databases: Design, Implementation, and Application Development

CHAPTER 11

CREATING ACCDE FILE .........................................................257

ACCDE FILES .................................................................................................. 257 CHAPTER 12

DEVELOPING SWITCH BOARD..............................................261

SWITCH BOARD ............................................................................................... 261 CRATING A SWITCH BOARD FOR IMCS .................................................................. 261 Creating Switch Board Items .................................................................... 262 Setting Properties of Switch Board Items.................................................. 263 CHAPTER 13

MAINTAINING THE DATABASE ............................................273

DOCUMENTING YOUR DATABASE OBJECTS ............................................................. 273 ANALYZING DATABASE PERFORMANCE .................................................................. 276 ENCRYPTING YOUR DATABASE ............................................................................. 278 Opening a Database Encrypted with a Password...................................... 279 Removing Database Password ................................................................. 280 UPDATING A DATABASE USING A QUERY................................................................ 280 CHANGING THE NAVIGATION PANE VIEW ............................................................... 282 COMPACTING A DATABASE ................................................................................. 284 TRUSTING A DATABASE ...................................................................................... 285 BACKUP AND RESTORE A OF A DATABASE ............................................................... 286 Backup a Database.................................................................................. 286 Restoring a Database .............................................................................. 287 REPAIRING A DATABASE ..................................................................................... 289 CHAPTER 14

RUNNNING DATABASE ON NETWORK .................................293

SHARING AN ACCESS DATABASE OVER NETWORK ..................................................... 293 SPLITTING THE DATABASE ................................................................................... 294 RESTRICTING CHANGES TO THE DESIGN OF THE FRONT-END DATABASE .......................... 297 DISTRIBUTING THE FRONT-END DATABASE.............................................................. 297 CHANGING BACK-END DATABASE USED ................................................................. 297

17