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 不对,该怎么改?
这个问题第1个回答:
示例
SQL code
alter table TBName add ColumnName int not null check (ColumnName >=0 and ColumnName<=100) default 0
这个问题第2个回答:
alter table TBName add ColumnName int not null check (ColumnName >=0 and ColumnName <=100) default 0
不行。。。
这个问题第3个回答:
alter table TBName add ColumnName int not null check (ColumnName >=0 and ColumnName <=100) default 0
不行。。。
这个问题第4个回答:
报什么错误?...
这个问题第5个回答:
SQL code
create table tmp1 (myid int)
alter table tmp1 add myid2 int not null check (myid2>=1 and myid2<=100) default 0
这个问题第6个回答:
create table tmp1 (myid int)
alter table tmp1 add myid2 int not null check (myid2>=1 and myid2 <=100) default 0
这个是可以的
这个问题第7个回答:
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
不行,字段定义语法错误。。。你试过没有?
这个问题第8个回答:
给你的示例语句测试通过
如果是报语法错误。如果你语句组合变量时有问题,你可以输出语句看下
VB code
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
这个问题第9个回答:
试过了,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 这句却可以。。疯了
这个问题第10个回答:
access的话,尝试用ADO连接,然后执行:
alter table TB add Col int not null constraint Col_Name check (Col >=0 and Col <=100) default 0
这个问题第11个回答:
谢谢,用两条语句终于搞定了。。。