Click to See Complete Forum and Search --> : delete from table rows where column is empty


ketanco
10-20-2008, 12:15 AM
Hello,
I am trying to delete rows from a table where one of the columns contain no data. I tried this:

delete from tablename where response column is null;

or tried this too:

delete from tablename where tablename.column is null;

didnt give error but when I checked my table I saw that it didnt delete those rows that has empty fields under that column.

WHen I checked my table structure, I saw that for that column I had put varchar(7) for data type and no to null.

Is it not working because I marked that column as no to null when I was creating the table? If so, what are the empty cells in that column considered? And how can I delete the rows that contain those empty cells?

chazzy
10-20-2008, 06:55 AM
delete from table where column = '';

gabriele
10-20-2008, 04:32 PM
if using sql server (MS) then use this command which handles both cases (null or empty)
delete from tablename where isnull(column,'')=''
this command will treat null content as '' empty string and delete it along with all rows with empty string in that field..

ketanco
10-22-2008, 08:49 PM
thanks... the one chazzy said worked. the other one gave error for some reason..

felgall
10-22-2008, 09:04 PM
Well if the column is defined as NOT NULL then attempting to delete the null entries will not find anything to delete. Note that there is a difference between an empty field and one which has had an empty string put in it and that is why null and an empty string are not the same thing.