MS Access - 允许null的sql表达式? [英] MS Access - sql expression for allow null?

查看:352
本文介绍了MS Access - 允许null的sql表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MS Access(2003)数据库。一旦我创建一个列,我使用sql语句设置NOT NULL:

  ALTER TABLE Table1 
ALTER column myColumn INTEGER not null

有没有办法改回回允许空值?我已经尝试过:

  ALTER TABLE Table1 
ALTER column myColumn INTEGER null



但没有...

解决方案

无法在中指定 null (尽管不是null 允许)



请参阅以下文档以及此关于此主题的讨论



语法

  ALTER TABLE table {ADD {COLUMN field type [ size]] [NOT NULL] [CONSTRAINT index] | ALTER COLUMN字段类型[(大小)] | CONSTRAINT multifieldindex} | DROP {COLUMN fields I CONSTRAINT indexname}} 




老学校解决方案: -




  • 创建一个新的temporal字段为null,相同的数据类型

  • 将新的临时字段更新为现有的NOT NULL字段

  • 删除旧的NOT NULL字段

  • 再次使用相同的数据类型创建具有相同数据类型的已删除列,不含NOT NULL

  • 将现有字段更新为临时字段



I use MS Access (2003) database. Once I create a column I set NOT NULL using sql statement:

ALTER TABLE Table1 
ALTER column myColumn INTEGER not null      

Is there a way to change it back to allow null values? I already tried:

ALTER TABLE Table1 
ALTER column myColumn INTEGER null      

but nothing...

解决方案

You cant specify null in ALTER TABLE (although not null is allowed)

See the below documentation and also this discussion on this toppic

Syntax

ALTER TABLE table {ADD {COLUMN field type[(size)] [NOT NULL]     [CONSTRAINT index] |     ALTER COLUMN field type[(size)] |     CONSTRAINT multifieldindex} |     DROP {COLUMN field I CONSTRAINT indexname} }


Old School Solution:-

  • create a new temporray field as null with the same datatype
  • update the new temporary field to the existing NOT NULL field
  • drop the old NOT NULL field
  • create the droped column with the same datatype again without NOT NULL
  • update the existing field to the temporary field
  • if there have been indices on the existing field, recreate these
  • drop the temporary field

这篇关于MS Access - 允许null的sql表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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