Access一些應用

2021-07-14 11:59:07 字數 2888 閱讀 4735

1,access資料庫字段型別說明以及與sql之間的對照關係

access允許九種資料型別:文字、備註、數值、日期/時間、貨幣、自動編號、是/否、ole物件、超級鏈結、查詢嚮導。

文字 nvarchar(n) 

備註 ntext 

數字(長整型) int 

數字(整型) smallint 

數字(單精度) real 

數字(雙精度) float 

數字(位元組) tinyint 

貨幣 money 

日期 smalldatetime 

布林 bit 

附:轉換成sql的指令碼。

alter table tb alter column aa byte 數字[位元組] 

alter table tb alter column aa long 數字[長整型] 

alter table tb alter column aa short 數字[整型] 

alter table tb alter column aa single 數字[單精度 

alter table tb alter column aa double 數字[雙精度] 

alter table tb alter column aa currency 貨幣 

alter table tb alter column aa char 文字 

alter table tb alter column aa text(n) 文字,其中n表示字段大小 

alter table tb alter column aa binary 二進位制 

alter table tb alter column aa counter 自動編號 

alter table tb alter column aa memo 備註 

alter table tb alter column aa time 日期/時間

2,操作語句,注意:一些語句在access中不支援但可以在ado中執行。

a,建立表

create table tb

(id counter primary key,

username varchar(50) not null,

*** int not null

)id counter 設定為自動編號

不能使用default設定預設值,但可以在ado中使用,如:conn.execute "create table a(column1 int default 0) "

b,修改表

修改字段:alter table tb alter column username varchar(60)

增加字段:alter table tb add column remark memo,,addtime time

刪除字段:alter table tb drop column remark

c,建立和刪除欄位的索引

有重複索引:create index iusername on tb (username)

無重複索引:create unique index iusername on tb (username)

刪除索引 :drop index iusername on tb

d,建立檢視和儲存過程,該語句要在ado中執行才能建立,直接在access建立不了建立檢視 :conn.execute "create view tb_view as select * from tb"

建立儲存過程:conn.execute "create procedure getuserinfo(id int) as select * from tb where id = id"

e,跨資料庫聯表查詢,使用 in "資料庫路徑",外部資料庫不能帶密碼

select a.*,b.* from tab1 a,tab2 b in 'c://www/demo/db2.mdb' where a.id = b.id

f,隨機抽取n條資料

access :select top 10 * from 表 order by rnd(id)

sql server:select top 10 * from 表 order by newid()

3,access系統表

如果想判斷access中是否存在某個表怎辦?可以查詢系統表msysobjects,但該錶在access中預設是隱藏的。如果需要操作這幾個表,需要對相關的許可權進行相應的設定,具體如下:

access 2003:

第一步:把系統表顯示出來:工具---------->選項 在顯示標籤中選中 「系統物件」

第二步:設定許可權: 工具----------〉安全-----------〉使用者與組的許可權 在「物件名稱」裡面選中msysobjects,在「許可權"標籤當中設定許可權。 

access 2000:

第一步:顯示系統表

選單:【工具】>【選項】

選項卡:試圖

顯示:系統物件

第二步:設定系統表的操作許可權

選單:【工具】>【安全】>【使用者與組許可權】

物件名稱:選擇需要設定許可權的系統表名稱(msysobjects)

許可權:復選擇「查詢資料」,「更新資料」,「插入資料」,「刪除資料」

第三步:確定按鈕,ok!

4,access資料分表

當乙個表中存在著大資料時可以對該錶進行切分以提高讀取速度,切分方法和其他資料庫切分方法一樣,一般使用橫向切分。

Access 一些內部函式 Access 幫助裡

有些東西就在那裡擺著,只是大家都不知道罷了 以下東西摘至access幫助 字串函式 vba 函式 transact sql 標量函式 asc x ascii x chr x char x lcase x lcase x lower x len x datalength x ltrim x ltrim...

筆記 一些access操作,基於DAO

鑑於csdn部落格更新之於本人來講是乙個失敗,導致本博文排版一片混亂。現將其轉到 1.獲得所有的資料表的名稱,並基於表名來進一步操作。2.為資料表增加某些字段 field 3.判斷某字段的一些記錄是否為空,是則補充資料。4.建立具有同樣表結構的新錶 5.修改表名 6.判斷表是否存在。否,則建立之 c...

C 操作ACCESS的一些常用類

using system using system.configuration using system.collections using system.data using system.data.oledb namespace mydata 關閉資料庫鏈結 public static void...