如何从表中的列中删除默认值? [英] How do you drop a default value from a column in a table?

查看:45
本文介绍了如何从表中的列中删除默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改列以删除默认值?

How do you alter a column to remove the default value?

该列的创建方式为:

 ALTER table sometable Add somecolumn nchar(1) NOT NULL DEFAULT 'N'

然后更改为:

 alter table sometable alter column somecolumn nchar(1) null

这允许空值,但保留默认值.你怎么能删除它?

That allows nulls, but the default value remains. How can you remove it?

推荐答案

是默认约束,需要执行一个:

Its a default constraint, you need to perform a:

ALTER TABLE {TableName} 
DROP CONSTRAINT ConstraintName

如果您在创建约束时没有指定名称,那么 SQL Server 会为您创建一个.您可以使用 SQL Server Management Studio 通过浏览到表,打开其树节点,然后打开 Constraints 节点来查找约束名称.

If you didn't specify a name when you created the constraint, then SQL Server created one for you. You can use SQL Server Management Studio to find the constraint name by browsing to the table, opening its tree node, then opening the Constraints node.

如果我没记错的话,约束将被命名为 DF_SomeStuff_ColumnName.

If I remember correctly, the constraint will be named something along the lines of DF_SomeStuff_ColumnName.

Josh W. 的 答案包含一个链接到SO 问题 向您展示如何使用 SQL 而不是使用 Management Studio 界面查找自动生成的约束名称.

Josh W.'s answer contains a link to a SO question that shows you how to find the auto generated constraint name using SQL instead of using the Management Studio interface.

这篇关于如何从表中的列中删除默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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