I am trying to add a column to a table to save time in seconds. I already have a TIME column, lets call it column A, from which I want to seed data to my new column, lets call it column B.Queries are being generated via Entity Framework Code First Migrations.
They boil down to something like this, and if I try to run the script created by it, I get an error that says Invalid column name. Please help in clarifying why this is happening.
It renders all queries with an idea to do something on a column if it exists a bit impossible to run.\
I really can't understand what is wrong here.
ALTER TABLE [dbo].[TheTable] ADD [ColumnB] [float] NOT NULL DEFAULT 0 IF EXISTS(SELECT 1 FROM sys.columns WHERE Name = N'ColumnA' AND Object_ID = Object_ID(N'TheTable')) AND EXISTS(SELECT 1 FROM sys.columns WHERE Name = N'ColumnB' AND Object_ID = Object_ID(N'TheTable')) BEGIN UPDATE dbo.TheTable SET ColumnB = -DATEDIFF(SECOND, ColumnA, 0); END ALTER TABLE [dbo].[TheTable] DROP COLUMN [ColumnA]