是/否字段的默认值

时间:2021-12-14 17:09:59

Struggling with an extremely easy issue, however, due to the lack of a more specific error message from ADO, I can't figure it out.

然而,由于缺乏来自ADO的更具体的错误消息,我遇到了一个非常简单的问题,我无法弄明白。

I need to add a new column in a table using SQL, the column type is a YESNO, however, I also want to set it's default value to TRUE|YES or whatever the brilliant engineers thought to name it ... this is what I have:

我需要使用SQL在表中添加一个新列,列类型是YESNO,但是,我还想将它的默认值设置为TRUE | YES或者不管那些出色的工程师想要命名它......这就是我的意思有:

ALTER TABLE TABLENAME
ADD COLUMN VISIBLE YESNO DEFAULT YES; /* the engine complains, 1 is also not ok, true is not ok, what is OK? */

If I remove everything after default the SQL will be executed as expected...

如果我在默认情况下删除所有内容,SQL将按预期执行...

Thank you!

谢谢!

EDIT:

编辑:

Just in case someone else hits this "wall", here's my final SQL:

以防其他人点击这个“墙”,这是我的最终SQL:

ALTER TABLE TABLENAME
ADD COLUMN VISIBLE YESNO -1;

1 个解决方案

#1


2  

You need to execute against a connection to use Default, eg:

您需要针对连接执行以使用Default,例如:

s = "ALTER TABLE TABLE1 ADD COLUMN VISIBLE YESNO DEFAULT true"
CurrentProject.Connection.Execute s

-1 is fine, too. If you want to display a checkbox, you will need VBA.

-1也很好。如果要显示复选框,则需要VBA。

#1


2  

You need to execute against a connection to use Default, eg:

您需要针对连接执行以使用Default,例如:

s = "ALTER TABLE TABLE1 ADD COLUMN VISIBLE YESNO DEFAULT true"
CurrentProject.Connection.Execute s

-1 is fine, too. If you want to display a checkbox, you will need VBA.

-1也很好。如果要显示复选框,则需要VBA。