Article ID: 115833
Article Last Modified on 10/29/2003
CREATE TABLE
DROP TABLE
DROP INDEX
ALTER TABLE
CREATE INDEX
db.Execute "DROP TABLE [Another Table];"
CREATE TABLE table (field1 type [(size)] [index1] [, field2 type
[(size)] [index2] [, ...]] [, multifieldindex [, ...]])
DROP {TABLE table | INDEX index ON table}
ALTER TABLE table {ADD {[COLUMN] field type[(size)] [CONSTRAINT index]
| CONSTRAINT multifieldindex}
| DROP {[COLUMN] field I CONSTRAINT indexname} }
CREATE [ UNIQUE ] INDEX index
ON table (field[, ...])
[WITH { PRIMARY | DISALLOW NULL | IGNORE NULL }]
VERSION 2.00
Begin Form Form1
Caption = "Form1"
ClientHeight = 4965
ClientLeft = 1095
ClientTop = 1485
ClientWidth = 8460
Height = 5370
Left = 1035
LinkTopic = "Form1"
ScaleHeight = 4965
ScaleWidth = 8460
Top = 1140
Width = 8580
Begin ListBox List1
Height = 2175
Left = 120
Sorted = -1 'True
TabIndex = 5
Top = 600
Visible = 0 'False
Width = 2775
End
Begin CommandButton Command2
Caption = "Create a new Index for BIBLIO.MDB"
Height = 495
Left = 3240
TabIndex = 4
Top = 600
Visible = 0 'False
Width = 4335
End
Begin CommandButton Command4
Caption = "Drop the new Index from BIBLIO.MDB"
Height = 495
Left = 3240
TabIndex = 3
Top = 2040
Visible = 0 'False
Width = 4335
End
Begin CommandButton Command3
Caption = "Alter the new Table in BIBLIO.MDB"
Height = 495
Left = 3240
TabIndex = 2
Top = 1320
Visible = 0 'False
Width = 4335
End
Begin CommandButton Command5
Caption = "Drop the new Table from BIBLIO.MDB"
Height = 495
Left = 3240
TabIndex = 1
Top = 2760
Visible = 0 'False
Width = 4335
End
Begin CommandButton Command1
Caption = "Create a new Table for BIBLIO.MDB"
Height = 495
Left = 3240
TabIndex = 0
Top = 0
Width = 4335
End
Begin Label Label1
Caption = "List of Table Names:"
Height = 375
Left = 480
TabIndex = 6
Top = 120
Visible = 0 'False
Width = 2175
End
End
Sub Command1_Click ()
Dim db As database
' Change the following two lines into one single line:
MySQL = "CREATE TABLE [Another Table] ([First Name] TEXT,
[Last Name] TEXT);"
Set db = OpenDatabase("C:\VB\BIBLIO.MDB")
db.Execute MySQL
command2.Visible = True
For i% = 0 To db.TableDefs.Count - 1
list1.AddItem db.TableDefs(i%).Name
Next i%
label1.Visible = True
list1.Visible = True
db.Close
command2.setfocus
End Sub
Sub Command2_Click ()
Dim db As database
' Change the following two lines into one single line:
MySQL = "CREATE UNIQUE INDEX MyIndex ON [Another Table] ([Last Name])
WITH PRIMARY;"
Set db = OpenDatabase("C:\VB\BIBLIO.MDB")
db.Execute MySQL
command3.Visible = True
list1.Clear
For i% = 0 To db.TableDefs("Another Table").Indexes.Count - 1
list1.AddItem db.TableDefs("Another Table").Indexes(i%).Name
Next i%
label1.Caption = "List of Index Names for 'Another Table'"
db.Close
command3.setfocus
End Sub
Sub Command3_Click ()
Dim db As database
MySQL = "ALTER TABLE [Another Table] ADD COLUMN Salary CURRENCY;"
Set db = OpenDatabase("C:\VB\BIBLIO.MDB")
db.Execute MySQL
command4.Visible = True
list1.Clear
For i% = 0 To db.TableDefs("Another Table").Fields.Count - 1
list1.AddItem db.TableDefs("Another Table").Fields(i%).Name
Next i%
label1.Caption = "List of Field Names for 'Another Table'"
db.Close
command4.setfocus
End Sub
Sub Command4_Click ()
Dim db As database
MySQL = "DROP INDEX MyIndex ON [Another Table];"
Set db = OpenDatabase("C:\VB\BIBLIO.MDB")
db.Execute MySQL
command5.Visible = True
list1.Clear
For i% = 0 To db.TableDefs("Another Table").Indexes.Count - 1
list1.AddItem db.TableDefs("Another Table").Indexes(i%).Name
Next i%
label1.Caption = "List of Index Names for 'Another Table'"
db.Close
command5.setfocus
End Sub
Sub Command5_Click ()
Dim db As database
MySQL = "DROP TABLE [Another Table];"
Set db = OpenDatabase("C:\VB\BIBLIO.MDB")
db.Execute MySQL
list1.Clear
For i% = 0 To db.TableDefs.Count - 1
list1.AddItem db.TableDefs(i%).Name
Next i%
label1.Caption = "List of Table Names"
db.Close
End Sub
Additional query words: 3.00
Keywords: KB115833