For some reason I think the solution to this is very simple. I however can not find it.
I need to drop a table in which the structure may be obsolete (the data will always be). Then I need to recreate the table based on another table or view's structure. What I have works when the table is of the same structure or does not exists, kind of like the Drop Table command isn't executing at all or in time. What am I missing?
I need to drop a table in which the structure may be obsolete (the data will always be). Then I need to recreate the table based on another table or view's structure. What I have works when the table is of the same structure or does not exists, kind of like the Drop Table command isn't executing at all or in time. What am I missing?
Code:
Create Procedure spSyncTest
As
If Exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tbl_Indexed_Scores_Combined]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
Exec('Drop Table [dbo].[tbl_Indexed_Scores_Combined]')
-- Start : Resynce tbl_Indexed_Scores_Combined --
Select * Into [dbo].[tbl_Indexed_Scores_Combined] From [dbo].[vw_Scores_Combined] Where 1 = 0
ALTER TABLE [dbo].[tbl_Indexed_Scores_Combined] WITH NOCHECK ADD
CONSTRAINT [PK_tbl_Indexed_Scores_Combined] PRIMARY KEY CLUSTERED
(
[QuestionID],
[SerialID]
) WITH FILLFACTOR = 90 ON [PRIMARY]
Insert Into [dbo].[tbl_Indexed_Scores_Combined] Select * From [dbo].[vw_Scores_Combined]