数据库编程与Visual Basic编辑器全解析
1. 数据库定义语言(DDL)操作
在数据库编程中,数据库定义语言(DDL)用于创建和定义数据库对象。以下是一段使用DDL创建数据库、表和索引的示例代码:
Dim idxBooks As Index
' Use the default workspace, called Workspaces(0)
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",