急求一个创建ACCESS表的语句(100分)

  • 主题发起人 主题发起人 bjaman
  • 开始时间 开始时间
B

bjaman

Unregistered / Unconfirmed
GUEST, unregistred user!
久疏于ACCESS,记不清建表的数据类型了,求一个建表语句示例,要求有整型,字符型,备注型,日期型,布尔型字段....
 
前些时间总结,不全,但差不多可以用了
用SQL语句创建Access表

----------------------------------------------------------------------------
类型名称 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) --创建无重复索引注意:主键字段会被自动建立为没有重复的索引

procedure 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;
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3529812 帮忙啊!
 
谢谢hzjone,我试试....
 
接受答案了.
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
927
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部