是否可以在SQL中将主键更新为null [英] Is it possible to update a primary key to null in SQL

查看:96
本文介绍了是否可以在SQL中将主键更新为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server 2008中有一个带有主键的表.
当我尝试将主键更新为null时,这正在发生,这是SQL的功能,您可以将主键更新为null吗?

I have a table with a primary key in SQL Server 2008.
When I try to update the primary key to null, it is happening, Is this a feature of SQL that you can update the primary key to null?

推荐答案

简而言之,主键永远不能为空.

如果需要有时可能为空的键,请考虑使用唯一键.

参考文献:
-主键 [唯一键 [
To simply put it, primary key can never be null.

If you need a key that can sometimes be null, consider using a unique key.

References:
- Primary key[^]
- Unique key[^]


绝对不是我亲爱的...

主键列始终保持数据不为空和唯一.
Absolutely not my dear...

Primary key column always keeps data NOT NULL and UNIQUE.


谢谢!
我想我出了问题所在.通过UI如何在主列中插入一个空字符串.因此,它实际上不是空值.
Thanks!
I think I got where I was going wrong. Some how through the UI, an empty string was getting inserted into the primary column . So, it was not actually a null value.


这篇关于是否可以在SQL中将主键更新为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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