简体   繁体   English

如何从表中删除记录?

[英]How do I delete a record from a table?

How do I delete a record from a table? 如何从表中删除记录?

For example, the table has two columns: eno and ename . 例如,该表具有两列: enoename I want to delete one value in ename from the table: 我想从表中删除ename中的一个值:

Eno Ename 伊诺 的ename

1 asha 1莎

2 bimal 2比利

I want to delete the value 'bimal' . 我想删除值'bimal'

Your question is somewhat ambiguous. 您的问题有点模棱两可。

If, as in the title, you want to delete the record containing 'Bimal' then you would write something like: 如果要删除标题中包含“ Bimal”的记录 (如标题中所示),则应编写如下内容:

DELETE FROM [table_name] WHERE Eno = 2

However if, as the question body implies, you mean you want to keep the record but delete the value 'Bimal' from it, then you would write something like: 但是,如果如问题正文所暗示的那样,您表示要保留记录,但要从中删除 “ Bimal”,则应编写如下内容:

UPDATE [table_name] SET Ename = NULL WHERE Eno = 2
DELETE FROM mytable WHERE ename = 'bimal'

Use a parameterised statement in real code though, rather than including the value directly in the SQL. 但是,请在真实代码中使用参数化语句,而不是直接在SQL中包含值。 How you do this will depend on your client environment, but the SQL will probably look something like: 如何执行此操作将取决于您的客户端环境,但是SQL可能类似于:

DELETE FROM mytable WHERE ename = @name

Then @name is the parameter whose value you'd provide as a separate piece of data. 然后@name是参数,您将其值作为单独的数据提供。 Then you don't need to worry about escaping it if it contains quotes etc. 然后,如果它包含引号等,则无需担心转义。

Note that so far all the answers (except one that's been deleted) have been deleting the whole row. 请注意,到目前为止,所有答案(已删除的答案除外)都已删除了整行。 Is this what you want, or do you actually want to just "remove" the ename value for that row (by overwriting it with NULL or an empty string)? 这是您想要的,还是您实际上只是想“删除”该行的ename值(通过用NULL或空字符串覆盖它)?

You need to learn some fundamental things. 您需要学习一些基本知识。 You should read some book on SQL first, or make some online tutorial. 您应该先阅读有关SQL的书,或者进行一些在线教程。 Google will help you with that. Google会帮助您。 One thing you need to know, is this: there is an SQL Standard that works on all databases / DBMS and that is what you should learn first. 您需要知道的一件事是:有一个适用于所有数据库/ DBMS的SQL标准,这是您应该首先学习的。

After this, you can take a look at T-SQL, the SQL dialect for Microsoft SQL Server. 之后,您可以看一下T-SQL,这是Microsoft SQL Server的SQL方言。 And then you have to find the online help for it and learn to use it. 然后,您必须找到它的在线帮助并学习使用它。 The syntax for the delete statement you ask for is described here . 您所要求的delete语句的语法在此处描述。

Good luck 祝好运

DELETE FROM table WHERE Ename = 'bimal'; 从表WHERE中删除Ename ='bimal'; or DELETE FROM table WHERE Eno = 2; 或DELETE FROM table WHERE Eno = 2;

delete from tablename where eno = 2

assuming tablename is the name of your table. 假设tablename是表的名称。

Look for "DELETE statement [SQL Server]" in Books Online for the complete syntax. 在联机丛书中查找“ DELETE语句[SQL Server]”以获取完整的语法。

It sounds like you just want to update a value in the Ename column. 听起来您只想更新Ename列中的值。

Do this: 做这个:

UPDATE <table_name> SET Ename='' WHERE Eno=2;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM