使用 TSQL 更改现有列的类型 - 约束怎么样?
我想将列的类型从 bit 更改为tinyint。这是我的 SQL:
ALTER TABLE table ALTER COLUMN column TINYINT NOT NULL
这告诉我列有一个约束。我放弃了约束,但这真的有必要吗?这样做的正确方法是什么?我想以后我也需要约束。
谢谢 :)
I want to alter the type of a column from bit to tinyint. This is my SQL:
ALTER TABLE table ALTER COLUMN column TINYINT NOT NULL
This tells me that there is a constraint for column. I dropped the constraint, but is this really necessary? Whats the right way to do this? I think afterwards I need a constraint, too.
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是必要的。
对
BIT
字段的约束不可能对tinyint
字段起作用,因为它们是不同的数据类型。1
的BIT
值并不意味着“第一”,它表示true
或yes
或 <代码>上。就好像你有一条规则:
...然后您将该值更改为十进制数据类型。小数不可能满足约束条件。
在 DDL 操作之前,您必须禁用约束,因为它们可能在更改后无效。
Yes this was necessary.
A constraint on a
BIT
field can't possibly work on atinyint
field since they are different datatypes.The
BIT
value of1
doesn't mean "The number one", it indicatestrue
oryes
oron
.It's as if you had a rule:
...and then you changed the value to be a decimal datatype. The decimal can't possibly meet the criteria of the constraint.
Before DDL operations you must disable constraints since they may be invalid after the change.