一个SQL语句:alter table chat add " & Text1.Text & " int not null default 0

hahatju 2009-03-09 05:26:16
alter table chat add " & Text1.Text & " int not null default 0
意思是添加一个字段,并设置为非空,默认值为0
但是我需要设置有效性规则,比如大于0,小于100
alter table chat add " & Text1.Text & " int not null check (>=0 and <=100) default 0 不对,该怎么改?
...全文
386 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
hahatju 2009-03-10
  • 打赏
  • 举报
回复
试过了,SQL server里面可以用。但是access里面用不了。。。不是变量的问题,alter table tmp1 add myid2 int not null check (myid2>=1 and myid2 <=100) default 0也不行,但alter table tmp1 add myid2 int not null default 0 这句却可以。。疯了
vbman2003 2009-03-10
  • 打赏
  • 举报
回复
给你的示例语句测试通过

如果是报语法错误。如果你语句组合变量时有问题,你可以输出语句看下


dim s as string
s="alter table chat add " & Text1.Text & " int not null check (" & Text1.Text & " >=0 and " & Text1.Text & " <=100) default 0"
'输出检查:
debug.print s

hahatju 2009-03-10
  • 打赏
  • 举报
回复
TO :vbman2003
报:字段定义语法错误。

TO:clear_zero
alter table tmp1 add myid2 int not null default 0 这句可以,但alter table tmp1 add myid2 int not null check (myid2>=1 and myid2 <=100) default 0
不行,字段定义语法错误。。。你试过没有?
hahatju 2009-03-10
  • 打赏
  • 举报
回复
谢谢,用两条语句终于搞定了。。。
vbman2003 2009-03-10
  • 打赏
  • 举报
回复
access的话,尝试用ADO连接,然后执行:
alter table TB add Col int not null constraint Col_Name check (Col >=0 and Col<=100) default 0
clear_zero 2009-03-09
  • 打赏
  • 举报
回复
create table tmp1 (myid int)
alter table tmp1 add myid2 int not null check (myid2>=1 and myid2<=100) default 0


这个是可以的
winter75 2009-03-09
  • 打赏
  • 举报
回复


create table tmp1 (myid int)
alter table tmp1 add myid2 int not null check (myid2>=1 and myid2<=100) default 0
vbman2003 2009-03-09
  • 打赏
  • 举报
回复
报什么错误?...
hahatju 2009-03-09
  • 打赏
  • 举报
回复
alter table TBName add ColumnName int not null check (ColumnName >=0 and ColumnName<=100) default 0
不行。。。
hahatju 2009-03-09
  • 打赏
  • 举报
回复
alter table TBName add ColumnName int not null check (ColumnName >=0 and ColumnName<=100) default 0
不行。。。
vbman2003 2009-03-09
  • 打赏
  • 举报
回复
示例


alter table TBName add ColumnName int not null check (ColumnName >=0 and ColumnName<=100) default 0

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧