access操作mysql_Access数据库SQL语句操作

笔记疑问:ACCESS中一直没能找到用sql语句更改列名、创建约束、设置默认值。

经过测试,建表时也不能同时设置默认值。如下列建表语句会报错(但把第三句的default 0去掉就能执行):

create table test (

id counter,

name char(20) not null,

age integer not null default 0,

notes memo,

primary key (id)

);

1、建表语句:

autincrement就跟MsSqlServer中的identity (1,1)一样的效果,实现自增量。

create table test (

Sn autoincrement,

testId integer not null,

testName char(30) not null,

testMemo memo null,

sdate datetime,

testCol text null,

primary key (Sn)

);

//自动增量,也可在建表时表述为:Id counter,

独立增加主键:

alter table test add constraint pk_testid primary key (id);

增加外接关联表:

注意:下面这句在access执行不了:

alter table newsinfo add constraint fk_clid FOREIGN KEY (newsclassid) references newsclass (id) ON UPDATE CASCADE ON DELETE CASCADE;

正确能执行的:

alter table newsinfo add constraint fk_clid FOREIGN KEY (newsclassid) references newsclass (id);

ALTER TABLE Table2 ADD CONSTRAINT Relation1 FOREIGN KEY ([Id]) REFERENCES Table1 ([Id]) ;

删除外接关联关系:

alter table newsinfo drop constraint fk_clid;

2、修改列类型:

改变列testcol的类型为memo,如:

alter table test alter column testcol memo;

alter table test alter column testcol long;

alter table test alter column testcol float;

alter table test alter column testcol money;

alter table test alter column testcol currency;

增加列:

alter table test add testcoladd long;

删除列:

alter table test drop testcoladd;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值