在Access中使用sql語句創建表時指定字段類型
長度爲255的文本varchar
長度爲20的文本varchar(20)
日期時間datetime
數字byte或smallint或integer,或bit
自動編號:counter(1,1)
外健:constraint外健名
主鍵:primary key
小數:numeric
單精度:real
雙精度:float
備註:memo
貨幣:currency Ole對象:image
----------------------------------------------------------------------------
類型名稱 TYPE 備註
----------------------------------------------------------------------------
自動編號 integer + identity(1,1)
文本 varchar(50) 括號中的數字爲文本長度
長整型 integer
整型 short
雙精度型 double,float
單精度型 real
字節型 byte
小數 NUMERIC(6,2)
貨幣 money
備註 text
日期/時間 date,time,datetime
是/否 bit
OLE 對象 OLEObject
----------------------------------------------------------------------------
主鍵 primary key
必填 not null
默認值 default 當爲日期型時爲 default date()
-----------------------------------------------------------------------------
示例
表名 字段名 類型 附屬屬性 說明
------- --------- ------------ --------------------------------- -------------------
create table mytable (m_id integer identity(1,1) primary key ,--自增型,主鍵
m_class varchar(50) not null default 'AAA' ,--文本,非空,默認值'AAA'
m_int integer not null ,--長整型,非空
m_numeric NUMERIC(6,2) ,--小數型
m_money money not null default 0.00 ,--貨幣型,非空,默認值0.00
m_memo text ,--備註型
m_date date default date() ,--日期型,默認爲當前日期
m_boolean bit default yes ,--布爾型,默認爲yes
m_blob OLEObject ,--BLOB型
m_double double ,--雙精度型
m_float real) --單精度型
----------------------------------------------------------------------------------------------------------------------------
創建索引
示例1
create index myindex on mytable (m_class [DESC, ASC], m_int)
示例2
create unique index myindex on mytable (m_class) --創建無重複索引
注意:主鍵字段會被自動建立爲沒有重複的索引