Databases Reference
In-Depth Information
Set ws = DBEngine.Workspaces(0)
' Create a new database named LIBRARY
' in the default Workspace
Set dbLibrary = _
ws. CreateDatabase "d:\dao\library.mdb", _
dbLangGeneral)
' Create a new table called BOOKS
Set tblBooks = dbLibrary. CreateTableDef ("BOOKS")
' Define ISBN field and append to the
' table's Fields collection
Set fldBooks = tblBooks. CreateField ("ISBN", dbText)
fldBooks.Size = 13
tblBooks.Fields.Append fldBooks
' Define Title field and append to the
' table's Fields collection
Set fldBooks = tblBooks. CreateField ("Title", dbText)
fldBooks.Size = 100
tblBooks.Fields.Append fldBooks
' Add the table to the db's Tables collection
dbLibrary.TableDefs.Append tblBooks
' Create an index
Set idxBooks = tblBooks. CreateIndex ("ISBNIdx")
idxBooks.Unique = False
' Indices need their own fields
Set fldBooks = idxBooks. CreateField ("ISBN")
' Append to the proper collections
idxBooks.Fields.Append fldBooks
tblBooks.Indexes.Append idxBooks
As you can see, the clue that we are dealing with a DDL are the commands
CreateDatabase , CreateTableDef , CreateField , and CreateIndex (in boldface for
easier identification). You can also see from this code that the Jet DBMS uses the
collections to hold the properties of an object. For instance, the fields that we create for a
table must be appended to the Fields collection for that table. This has the advantage that
we don't need to keep a separate reference to each field—the collection does that for us.
This approach is typical of object-oriented programming.
7.6 Data Manipulation Languages
A DBMS must also provide a language designed to manipulate the data in a database.
This language is called a database manipulation language , or DML. To the database
programmer, however, the distinction between a DDL and a DML may be just a logical
one, defined more by the purpose of the language than the syntax.
 
Search WWH ::




Custom Search