Access数据表字段类型与建表示例

本文详细介绍了SQL中各种字段类型的使用方法及其特点,并通过示例展示了如何创建表及进行表结构调整,包括创建索引、修改字段属性、增加或删除列等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

-----------------------------------------------------------------

类型名称 TYPE 备注

-----------------------------------------------------------------

文本               Char(n) 其中n表示字段大小

文本               Varchar(n)

文本               Text

数字[字节]       Byte

数字[整型]       Short

数字[长整型]    Long, integer

数字[单精度]    Single, Real

数字[双精度]    Double, Float

数字[自动编号] Integer Identity(1,1)

数字[自动编号] Counter

二进制             Binary

货币                Currency, Money

备注                Memo

日期/时间         Date, Time, Datetime

是/否               Bit

OLE 对象         OLEObject

-----------------------------------------------------

主键 primary key

必填 not null

默认值 default 当为日期型时为 default date()

-----------------------------------------------------

 

 在使用Create Table 语句时, 尽量使用如下字段定义类型:

 Boolean、Integer、Long、Currency、Single、Double、Date、String 和 Variant(默认)

 

-----------------------------------------------------

 

示例

表名 字段名 类型 附属属性 说明

------- --------- ------------ --------------------------------- -------------------

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_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) --创建无重复索引

注意:主键字段会被自动建立为没有重复的索引

 

修改属性

ALTER TABLE Admin ALTER COLUMN UserName VarChar(200)

 

增加列

ALTER TABLE Admin ADD UserPass VARCHAR(50) NULL

 

删除列

ALTER TABLE Admin DROP COLUMN UserPass

 

该内容整理自 http://www.940194.cn/ShowData/2008-10/74.html

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值