如何使用SQL设置Access 2003字段的默认值? [英] How to set the default value of an Access 2003 field using SQL?

查看:322
本文介绍了如何使用SQL设置Access 2003字段的默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在MS Access中使用SQL设置字段的默认值?

How can I set the default value for a field using SQL in MS Access?

我试过这个但是出现语法错误:

I tried this but got a syntax error:

CREATE TABLE HELLO
( MUN INTEGER  NOT NULL,
ADD   CHAR(50) DEFAULT'16 asd ST.'
)


推荐答案

DEFAULT <仅当在ACE / Jet引擎的ANSI-92查询模式(然后只在SQL DDL中)时才支持code>和 CHAR 关键字。正如Jose Basilio指出, ADD 是一个保留字,必须使用方括号进行转义。此外,您需要在 DEFAULT 字和其子句之间(如Jose所示)有一个空格。

The DEFAULT and CHAR keywords are only supported when in the ACE/Jet engine's ANSI-92 Query Mode (and then only in SQL DDL). As Jose Basilio points out, ADD is a reserved word and must be escaped using square brackets. Also, you need a space between the DEFAULT word and its clause (as Jose has shown).

正在MS Access接口中的Query对象中执行SQL,您将需要从默认(ANSI-89查询模式)更改为ANSI-92查询模式。请参阅:关于ANSI SQL查询模式

If you are executing the SQL in a Query object in the MS Access interface you will need to change from the default (ANSI-89 Query Mode) to ANSI-92 Query Mode. See: About ANSI SQL query mode.

如果您以编程方式创建表,例如您正在使用DAO,然后尝试使用 CurrentProject.Connection.Execute Sql到这里,其中 CurrentProject.Connection 是一个ADO经典或其他OLE DB连接到您的数据源。

If you are creating the table programmatically e.g. you are using DAO then try using a CurrentProject.Connection.Execute "Sql goes here" where CurrentProject.Connection is an ADO classic or other OLE DB connection to your data source.

PS当然你希望你的列 HELLO.Mum :)

P.S. Surely you wanted you column to be HELLO.Mum :)

这篇关于如何使用SQL设置Access 2003字段的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆