以下代碼在WIN
//在之前uses ComObj
//聲明連接字符串
Const
SConnectionString =
+
//=============================================================================
// Procedure: GetTempPathFileName
// Author : ysai
// Date :
// Arguments: (None)
// Result : string
//=============================================================================
function GetTempPathFileName():string;
//取得臨時文件名
var
SPath
begin
GetTempPath(
GetTempFileName(SPath
result:=SFile;
DeleteFile(PChar(result));
end;
//=============================================================================
// Procedure: CreateAccessFile
// Author : ysai
// Date :
// Arguments: FileName:String;PassWord:string=
// Result : boolean
//=============================================================================
function CreateAccessFile(FileName:String;PassWord:string=
//建立Access文件
var
STempFileName:string;
vCatalog:OleVariant;
begin
STempFileName:=GetTempPathFileName;
try
vCatalog:=CreateOleObject(
vCatalog
result:=CopyFile(PChar(STempFileName)
DeleteFile(STempFileName);
except
result:=false;
end;
end;
//=============================================================================
// Procedure: CompactDatabase
// Author : ysai
// Date :
// Arguments: AFileName
// Result : boolean
//=============================================================================
function CompactDatabase(AFileName
//壓縮與修復數據庫
var
STempFileName:string;
vJE:OleVariant;
begin
STempFileName:=GetTempPathFileName;
try
vJE:=CreateOleObject(
vJE
format(SConnectionString
result:=CopyFile(PChar(STempFileName)
DeleteFile(STempFileName);
except
result:=false;
end;
end;
//=============================================================================
// Procedure: ChangeDatabasePassword
// Author : ysai
// Date :
// Arguments: AFileName
// Result : boolean
//=============================================================================
function ChangeDatabasePassword(AFileName
//修改ACCESS數據庫密碼
var
STempFileName:string;
vJE:OleVariant;
begin
STempFileName:=GetTempPathFileName;
try
vJE:=CreateOleObject(
vJE
format(SConnectionString
result:=CopyFile(PChar(STempFileName)
DeleteFile(STempFileName);
except
result:=false;
end;
end;
以下SQL語句在ACCESS XP的查詢中測試通過
建表:
Create Table Tab
ID Counter
Name string
Age integer
[Date] DateTime);
技巧:
自增字段用 Counter 聲明
字段名為關鍵字的字段用方括號[]括起來
建立索引:
下面的語句在Tab
Create Index iDate ON Tab
完成後ACCESS中字段Date索引屬性顯示為
下面的語句在Tab
Create Unique Index iName ON Tab
完成後ACCESS中字段Name索引屬性顯示為
下面的語句刪除剛才建立的兩個索引
Drop Index iDate ON Tab
Drop Index iName ON Tab
ACCESS與SQLSERVER中的UPDATE語句對比:
SQLSERVER中更新多表的UPDATE語句:
UPDATE Tab
SET a
FROM Tab
WHERE a
同樣功能的SQL語句在ACCESS中應該是
UPDATE Tab
SET a
WHERE a
即:ACCESS中的UPDATE語句沒有FROM子句
上例中如果Tab
UPDATE Tab
SET a
WHERE a
訪問多個不同的ACCESS數據庫
Select a
上面的SQL語句查詢出當前數據庫中Tab
缺點
補充:看到ugvanxk在一貼中的答復
Select * from [c:\aa\a
ACCESS XP測試通過
在ACCESS中訪問其它ODBC數據源
下例在ACCESS中查詢SQLSERVER中的數據
SELECT * FROM Tab
[ODBC;Driver=SQL Server;UID=sa;PWD=;Server=
外部數據源連接屬性的完整參數是:
[ODBC;DRIVER=driver;SERVER=server;DATABASE=database;UID=user;PWD=password;]
其中的DRIVER=driver可以在注冊表中的
HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST
中找到異構數據庫之間導數據參見 碧血劍 的
http://www
ACCESS支持子查詢
ACCESS支持外連接
LEFT JOIN 或 RIGHT JOIN
但不支持
FULL OUTER JOIN 或 FULL JOIN
ACCESS中的日期查詢
注意:ACCESS中的日期時間分隔符是#而不是引號
Select * From Tab
在DELPHI中我這樣用
SQL
[DateToStr(Date)]));
ACCESS中的字符串可以用雙引號分隔
From:http://tw.wingwit.com/Article/program/Delphi/201311/24888.html