| Fundamentals of Database Development | |
|
Before we start interacting with databases using Delphi, it is a good idea to get a feel what modern databases are about. Building a modern database application requires us to think of data in a relational way. The basic idea behind the relational model is that a database consists of a series of tables (or relations) that can be manipulated using operations that return tables or so-called views.
Simply put, a database is best described as a collection of related data. A database may include many different tables. Tables are like grids where columns are called fields and rows are called ... rows.
To fully address the concepts of database design and relational model we would need an extra online course. For a great overview check out the Fundamentals of Relational Database Design.
New...Database I hope you know that on this site there is a Members Area where Delphi developers can upload their free code applications and components. Each member has it's name, an email address and a possibly a web page.
If we would like to keep track of every application posted to this community we could assemble a database of three tables: Applications (general information about an application), Authors (who made the application) and Types (what kind of app is it). Let's see how to do just that:
Start Access and create a blank database named aboutdelphi.mdb. Create three tables in Design view: Applications, Authors and Types.
The Applications table contains fields that match the application description requirements: Name, Description, Author, Type, Size, Cost, DateUpl and Picture. Name, Description, Author and Type fields contain Text data, 50 characters by default. The Size filed is of a Number (Single) type - used to store the size of a file in Kb. The Cost field is a Currency field - if the app is shareware or commercial. The DateUpl field is a date/time value. The Picture is of a OLE Object type and will hold an (optional) picture for an application. Let the filed Name be the primary key.
The Authors table contains fields that match the application author requirements: AuthorName, Email and Web. All the fields contain character data (50 chars by default). Let the filed AuthorName be the primary key.
The Types table contains only one field: TypeName which is the primary key for this table. This table will be used to store the type of application (graphical, multimedia, database, ...)
We now only have to set up a relation in the relationships window and the database is ready.
When you think of a word database you should generally think of any type of data stored inside a computer - even a SomeFile.pas file (code to some Delphi unit) is some kind of database. Another type of database is a Word document or a simple .ini file. To access an .ini file we generally use routines and techniques for typed or untyped files.
Since this course will primarily focus on ADO/Access Delphi approach to database programming we will now see how to create a new .mdb database in MS Access.
If you have never built a database with MS Access, go see MS Access tutorials for a great info.
Let's see the structure of those tables:

Download aboutdelphi.mdb here! (~200 Kb)
Both relations should "Enforce Referential Integrity" with only "Cascade Update Related Records" check on.
Filling some data
In order to have some "dummy" data in a database fill in the Types table with the following 4 records: 'Game','Database','Internet','Graphics'. This values will be used when choosing the type of the application stored in the Applications table. Next, add one row to the Authors table: 'Delphi Guide', 'delphi.guide@about.com', 'http://delphi.about.com'. Finally let the only one row in the Applications table look like: 'Zoom', 'Zooming the Destop', 'Delphi Guide', 'Graphics', 10, 0, 02/20/2001. For the moment leave the last field (Picture) empty.
What to do with this "blank" database...I'll show you that in the following chapters of this course.
DB Course Next Chapter >>
>>
Chapter 2: Connecting to a database. BDE? ADO?

