Can you tell me how to avoid below mentioned exception ?
INSERT INTO [Migrated].[dbo].[Cities] (Name, ZipCode)
SELECT DISTINCT
a.City, a.ZipCode
What the error message says is that the IsDeleted
column is declared NOT NULL
and it does not have a default value. In this case, you are probably inserting non-deleted records by default, so you might want to change column:
alter table cities alter column IsDeleted int not null default 0;
Alternatively, you can write the query to include the column:
INSERT INTO [Migrated].[dbo].[Cities] (Name, ZipCode, IsDeleted)
select DISTINCT zl.City, zl.ZipCode,
from [Legacy].[dbo].[Ziplist] zl
where a.City is not null and a.ZipCode is not null;
These answers assume that IsDeleted
is an integer with "0" for false. If the values are stored differently, then the code needs to be modified appropriately.