本文介绍了SQL SET DEFAULT在MS Access中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MS Access中的SQL查询执行以下语句;

I am trying to execute the following statement using a SQL query within MS Access;

ALTER TABLE [table] ALTER COLUMN [column] SET DEFAULT 'default value'

但是,我得到一个显示错误Syntax error in ALTER TABLE statement.

However, I get a dialog displaying the error Syntax error in ALTER TABLE statement.

当我单击确定"时,它会突出显示单词"DEFAULT".我还尝试了以下语句;

And when I click OK it highlights the word DEFAULT. I also tried the following statement;

ALTER TABLE [table]
ADD CONSTRAINT [Default] DEFAULT 'default value' FOR [column]

我又遇到另一个错误Syntax error in CONSTRAINT clause.

在MS Access中设置默认值的正确语法是什么? db文件是Access 2003格式.

What is the correct syntax for setting a default value in MS Access? The db file is Access 2003 format.

推荐答案

使用Jet 4(Access 2000)的Access DDL中包含对DEFAULT的支持.但是,只能在从ADO连接执行的DDL中使用它.

Support for DEFAULT was included in Access DDL with Jet 4 (Access 2000). However it can only be used in DDL executed from an ADO connection.

这与Access 2007一起使用.

This worked with Access 2007.

CurrentProject.Connection.Execute "ALTER TABLE MyTable " & _
    "ALTER COLUMN field2 SET DEFAULT ""foo"";"

请注意,如果您的数据库文件是Access 97或更早版本,则将无法在DDL中设置字段DEFAULT值.

Note if your db file is Access 97 or earlier, you won't be able to set a field DEFAULT value from DDL.

这篇关于SQL SET DEFAULT在MS Access中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 09:10