Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete particular column value alone in postgresql database?

Tags:

sql

postgresql

I have one table. The table name is employee. I used below query.

delete department,name,bloodgroup from employee where employeeid=2;

But I am not able to delete this record alone. It is showing error. And I don't want to use update statement.

like image 252
user007 Avatar asked Jan 04 '12 11:01

user007


2 Answers

You can't delete single column entries with the delete SQL command. Only complete rows.

You can use the update command for that:

update employee 
set department = null, name = null, bloodgroup = null
where employeeid=2;
like image 73
juergen d Avatar answered Sep 30 '22 01:09

juergen d


The above solution won't work until NOT NULL constraint is dropped(removed) to do this:

ALTER TABLE employee;
ALTER COLUMN department DROP NOT NULL;

After this You can UPDATE the table as above

UPDATE employee SET department = null WHERE employeeid =2;

Hope this one helps Thank you!

like image 37
Anonymous Avatar answered Sep 30 '22 00:09

Anonymous