SQL 添加具有默认值的列 - Access 2003

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 23:16:32  来源:igfitidea点击:

SQL to add column with default value - Access 2003

sqlms-access

提问by Polsonby

Updating an old ASP/Access site for a client - I need SQL to add a column to an existing table and set a default value. Doesn't work - any ideas?

为客户端更新旧的 ASP/Access 站点 - 我需要 SQL 将一列添加到现有表并设置默认值。不起作用 - 有什么想法吗?

This works fine

这工作正常

ALTER TABLE documents ADD COLUMN membersOnly NUMBER

I want this to work:

我希望这个工作:

ALTER TABLE documents ADD COLUMN membersOnly NUMBER DEFAULT 0

Have googled and seen instructions for default values work for other field types but I want to add number. Thanks!

用谷歌搜索并查看了适用于其他字段类型的默认值说明,但我想添加数字。谢谢!

回答by zappan

Tools -> Options -> Tables/Queries -> (At the bottom right:) Sql Server Compatible Syntax - turn option on for this database.

工具 -> 选项 -> 表/查询 ->(在右下角:)Sql Server Compatible Syntax - 为这个数据库打开选项。

then you can execute your query:

然后你可以执行你的查询:

ALTER TABLE documents ADD COLUMN membersOnly NUMBER DEFAULT 0

回答by HansUp

With ADO, you can execute a DDL statement to create a field and set its default value.

使用 ADO,您可以执行 DDL 语句来创建字段并设置其默认值。

CurrentProject.Connection.Execute _
   "ALTER TABLE discardme ADD COLUMN membersOnly SHORT DEFAULT 0"

回答by Polsonby

How are you connecting to the database to run the update SQL? You can use the ODBC compatible mode through ADO. Without opening the database in Access.

您如何连接到数据库以运行更新 SQL?您可以通过 ADO 使用 ODBC 兼容模式。无需在 Access 中打开数据库。

回答by mike nelson

You may find Sql Server Compatible Syntax is already turned on, so definately worth just trying to run the sql statement mentioned above (via an ADO connection from ASP) before resorting to taking the db offline. Thanks, this helped me out.

您可能会发现 Sql Server Compatible Syntax 已经打开,因此在使 db 脱机之前,绝对值得尝试运行上面提到的 sql 语句(通过来自 ASP 的 ADO 连接)。谢谢,这帮了我。

回答by user3921919

Tools -> Options -> Tables/Queries -> (At the bottom right:) Sql Server Compatible Syntax - turn option on for this database.

工具 -> 选项 -> 表/查询 ->(在右下角:)Sql Server Compatible Syntax - 为这个数据库打开选项。

is not found on MS Access 2010

在 MS Access 2010 上找不到