SQL SET DEFAULT 在 MS Access 中不起作用 [英] SQL SET DEFAULT not working in MS Access
问题描述
可能的重复:
ALTER TABLE 语句中的 DEFAULT 子句导致语法错误一个>
我正在尝试使用 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'
但是,我得到一个对话框,显示错误 ALTER TABLE 语句中的语法错误.
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]
并且我得到另一个错误 CONSTRAINT 子句中的语法错误.
And I get another error 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.
推荐答案
对 DEFAULT
的支持包含在 Access DDL with Jet 4 (Access 2000) 中.但是,它只能在从 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 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!