ALTER TABLE:使用默认值和复选框添加一个新的布尔列 [英] ALTER TABLE: Add a new boolean column with default value and checkbox
本文介绍了ALTER TABLE:使用默认值和复选框添加一个新的布尔列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将Boolean数据类型列添加到表中的正确Access DDL查询是什么?
What is the correct Access DDL query to add a Boolean datatype column to a table?
到目前为止,我已经看到了如下示例...
So far I've seen examples like the following...
ALTER TABLE MyTable ADD MyNewColumName BIT
但是自那以后,它们似乎并不是100%正确的
but they do not seem to be 100% correct since
- Access不会将复选框控件应用于新添加的列,并且
- 该列的允许值似乎是
0
和-1
推荐答案
DAO示例.
''Requires reference to Microsoft DAO 3.6 Object Library
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim db As Database
Dim strSQL As String
Set db = CurrentDb
''Create a table ...
strSQL = "Create Table tblLTD (TheYesNoCheck YesNo, TheYesNoCombo YesNo)"
db.Execute strSQL
''It is now in the table collection, so ...
Set tdf = db.TableDefs("tblLTD")
''Change the way the YesNo fields display.
''A Checkbox
Set fld = tdf.Fields("TheYesNoCheck")
Set prp = fld.CreateProperty("DisplayControl", dbInteger, acCheckBox)
fld.Properties.Append prp
''A combobox
Set fld = tdf.Fields("TheYesNoCombo")
Set prp = fld.CreateProperty("DisplayControl", dbInteger, acComboBox)
fld.Properties.Append prp
''We will need a format
Set prp = fld.CreateProperty("Format", dbText, "Yes/No")
fld.Properties.Append prp
来自: http://wiki.lessthandot.com/index. php/Add_a_Display_Control_(Checkbox,_Combobox)_to_a_YesNo_Field
这篇关于ALTER TABLE:使用默认值和复选框添加一个新的布尔列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文