In this article, we would like to show you how to delete a row where the column is an empty string in MS SQL Server.
DELETE FROM [table_name] WHERE [column_name] = '';
If your column is NULL then the below query works:
DELETE FROM [table_name] WHERE [column_name] IS NULL;
To show how to delete rows with an empty string values, we will use the following table:
At the end of this article you can find database preparation SQL queries.
In this example, we will delete rows from
users table with empty
DELETE FROM [users] WHERE [email] = '';
CREATE TABLE [users] ( [id] INT IDENTITY(1,1), [name] VARCHAR(50) NOT NULL, [surname] VARCHAR(50) NOT NULL, [email] VARCHAR(50), PRIMARY KEY ([id]) );
INSERT INTO [users] ( [name], [surname], [email]) VALUES ('John', 'Stewart', 'email@example.com'), ('Chris', 'Brown', ''), ('Kate', 'Lewis',''), ('Ailisa', 'Gomez', 'firstname.lastname@example.org'), ('Gwendolyn', 'James', ''), ('Simon', 'Collins', ''), ('Taylor', 'Martin',''), ('Andrew', 'Thompson', 'email@example.com');