SQL 删除特定值的列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5126167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 09:28:38  来源:igfitidea点击:

Delete the column for the particular value

sqlsql-serversql-server-2005

提问by Gopal

Using Sql Server 2005

使用 SQL Server 2005

Table1

表格1

ID Name Value

001 Rajesh 90
002 Suresh 100
003 Mahesh 200
004 Virat 400
...

I want to delete the value from the table1 for the particular id

我想从 table1 中删除特定 id 的值

Tried Query

尝试查询

Delete value from table1 where id = '001'

The above query is not working.

上面的查询不起作用。

How to make a delete query for delete the particular column

如何进行删除查询以删除特定列

Need Query Help

需要查询帮助

回答by Mark Byers

There are at least two errors with your statement:

你的陈述至少有两个错误:

  • The word tablewill give a syntax error because it is a reserved word. You need to specify the table name of the specific table you wish to delete from.
  • Also you cannot write DELETE value FROM. It's just DELETE FROM. And note that it deletes the entire row, not just a single value.
  • 这个词table会给出一个语法错误,因为它是一个保留字。您需要指定要从中删除的特定表的表名。
  • 你也不能写DELETE value FROM. 这只是DELETE FROM。请注意,它会删除整行,而不仅仅是单个值。

A correct delete statement would look like this:

正确的删除语句如下所示:

DELETE FROM table1
WHERE id = '001'

However if you want to change a single value to NULL you should use an UPDATE statement.

但是,如果要将单个值更改为 NULL,则应使用 UPDATE 语句。

UPDATE table1
SET value = NULL
WHERE id = '001'

Of course this assumes that the column is nullable. If not, you'll have to fix that first. See this question for details:

当然,这假设该列可以为空。如果没有,你必须先解决这个问题。有关详细信息,请参阅此问题:

回答by TigrisC

I think you want to set the value to null

我认为您想将该值设置为 null

update Table1 set value=NULL where id='001'