huiboy
iamond Access我有,不过不想用。之所以用了ADO,因为可能需要以
后进行远程交互。
avant:结果很不错,又研究了一下SQL语言,呵呵,下面是我最终的程序,通过
ADO创建Database,以及通过SQl创建里面的Table和Index。
procedure TDataModule1.CreateNewDatabase(DatabaseFileName: string);
var
cat:OleVariant;
begin
if FileExists(DatabaseFileName) then
begin
if MessageBox(Application.Handle,
PChar('Database ' + DatabaseFileName + ' has existed!'
+ #13#10 + 'Delete this database and create a new database ?'),
'Database Exists',MB_YESNO + MB_ICONWARNING + MB_DEFBUTTON2) = mrNo then
exit;
if not DeleteFile(DatabaseFileName) then
begin
MessageBox(Application.Handle,
PChar('Cannot delete database ' + DatabaseFileName),
'Delete Database Error!',MB_OK + MB_ICONERROR);
exit;
end;
end;
cat:=CreateOleObject('ADOX.Catalog');
cat.Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + DatabaseFileName);
if ConnectDatabase(DatabaseFileName) then
begin
adoquryClass.Close;
adoquryClass.SQL.Text := 'Create Table FaqClass ' +
'(' +
'ClassID INT not null,' +
'ClassTitle char(100) not null,' +
'ParentClassID INT not null,' +
'ClassType TINYINT DEFAULT 0' +
')';
adoquryClass.ExecSQL;
adoquryClass.Close;
adoquryClass.SQL.Text := 'Create UNIQUE Index ClassIDIndex ON FaqClass (ClassID)';
adoquryClass.ExecSQL;
adoquryClass.Close;
adoquryClass.SQL.Text := 'Create Index ClassTitleIndex ON FaqClass (ClassTitle)';
adoquryClass.ExecSQL;
adoquryClass.Close;
adoquryClass.SQL.Text := 'Create Index ParentClassIDIndex ON FaqClass (ParentClassID)';
adoquryClass.ExecSQL;
adoquryClass.Close;
adoquryClass.SQL.Text := 'Create Index ClassTypeIndex ON FaqClass (ClassType)';
adoquryClass.ExecSQL;
adoquryMemo.Close;
adoquryMemo.SQL.Text := 'Create Table FaqMemo' +
'(' +
'MemoID INT not null,' +
'ParentClassID INT not null,' +
'MemoTitle char(100) not null,' +
'MemoText TEXT,' +
'MemoPublic BIT DEFAULT 0,' + //缺省是不公开
'MemoLastModifyTime DATETIME' +
')';
adoquryMemo.ExecSQL;
adoquryMemo.Close;
adoquryMemo.SQL.Text := 'Create UNIQUE Index MemoIDIndex ON FaqMemo (MemoID)';
adoquryMemo.ExecSQL;
adoquryMemo.Close;
adoquryMemo.SQL.Text := 'Create Index ParentClassIDIndex ON FaqMemo (ParentClassID)';
adoquryMemo.ExecSQL;
adoquryMemo.Close;
adoquryMemo.SQL.Text := 'Create Index MemoTitleIndex ON FaqMemo (MemoTitle)';
adoquryMemo.ExecSQL;
adoquryMemo.Close;
adoquryMemo.SQL.Text := 'Create Index MemoPublicIndex ON FaqMemo (MemoPublic)';
adoquryMemo.ExecSQL;
adoquryMemo.Close;
adoquryMemo.SQL.Text := 'Create Index MemoLastModifyTimeIndex ON FaqMemo (MemoLastModifyTime)';
adoquryMemo.ExecSQL;
end;
end;