Home Forums SQL Server 2008 SQL Server 2008 - General check column exist or not if not exist assign null values for that column RE: check column exist or not if not exist assign null values for that column

  • Hi asrinu13,

    May you have some constraint in ref table, Please check it.

    Other wise no problem in transferring data from one table to another.

    Create table #temp1 (id int, name nvarchar(20), salary float)

    Insert into #temp1

    Select 1,'Mac',2000.00

    Union all

    Select 2, 'Jack',15000.50

    Union all

    Select 3, 'Jill',30000

    Go

    Select * from #temp1

    Go

    Create table #temp1ref (id int, name nvarchar(20), salary float)

    Insert into #temp1ref

    Select * from #temp1

    select * from #temp1ref

    Go

    Insert into #temp1ref

    Select * from #temp1

    Select * from #temp1ref

    Go

    Insert into #temp1

    Select 7,null,2000.00

    Go

    Insert into #temp1ref

    Select * from #temp1

    Select * from #temp1ref

    Go

    Drop table #temp1

    Drop table #temp1ref

    Vimal LohaniSQL DBA | MCP (70-461,70-462)==============================The greatest barrier to success is the fear of failure ** Success is a journey not a destination**Think before you print, SAVE TREES, Protect Mother Nature