Hi,
How do I delete a record from a table?
For example, the table has two columns: eno
and ename
. I want to delete one value in ename from the table:
Eno Ename
1 asha
2 bimal
I want to delete the value 'bimal'
.
Hi,
How do I delete a record from a table?
For example, the table has two columns: eno
and ename
. I want to delete one value in ename from the table:
Eno Ename
1 asha
2 bimal
I want to delete the value '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:
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:
UPDATE [table_name] SET Ename = NULL WHERE Eno = 2
DELETE FROM table WHERE Ename = 'bimal'; or DELETE FROM table 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. How you do this will depend on your client environment, but the SQL will probably look something like:
DELETE FROM mytable WHERE ename = @name
Then @name is the parameter whose value you'd provide as a separate piece of data. 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)?
delete from tablename where eno = 2
assuming tablename is the name of your table.
Look for "DELETE statement [SQL Server]" in Books Online for the complete syntax.
You need to learn some fundamental things. You should read some book on SQL first, or make some online tutorial. Google will help you with that. 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.
After this, you can take a look at T-SQL, the SQL dialect for Microsoft SQL Server. 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.
Good luck
It sounds like you just want to update a value in the Ename column.
Do this:
UPDATE <table_name> SET Ename='' WHERE Eno=2;