
ALTER TABLE dbo.VS4TEmpWorkCountMB
	DROP CONSTRAINT IF EXISTS VS4TEmpWorkCountVS4TEmpWorkCountMB
GO


ALTER TABLE dbo.VS4TEmpWorkCountMB
	DROP CONSTRAINT IF EXISTS VS4TEmployeeVS4TEmpWorkCountMB
GO


CREATE TABLE dbo.Tmp_VS4TEmpWorkCountMB
	(
	TECMTEWCNo nvarchar(30) NOT NULL,
	TECMLn int NOT NULL,
	TECMTJbMTJobNo nvarchar(50) NULL,
	TECMTJbMLn int NULL,
	TECMLevel int NULL,
	TECMTSpdStep int NULL,
	TECMTJPdNo nvarchar(30) NULL,
	TECMTSepCode nvarchar(30) NULL,
	TECMStepName nvarchar(50) NULL,
	TECMTEmpCode nvarchar(30) NULL,
	TECMWorkDate datetime NULL,
	TECMStartTime datetime NULL,
	TECMEndTime datetime NULL,
	TECMQuantity float(53) NULL,
	TECMCost float(53) NULL,
	TECMTotal float(53) NULL,
	TECMRemark nvarchar(150) NULL,
	TECMFlag1 smallint NULL,
	TECMFlag2 smallint NULL,
	TECMFlag3 smallint NULL,
	TECMRefNo nvarchar(30) NULL,
	TECMType smallint NULL
	)  ON [PRIMARY]
GO
IF EXISTS(SELECT * FROM dbo.VS4TEmpWorkCountMB)
	 EXEC('INSERT INTO dbo.Tmp_VS4TEmpWorkCountMB (TECMTEWCNo, TECMLn, TECMTJbMTJobNo, TECMTJbMLn, TECMTSpdStep, TECMTJPdNo, TECMTSepCode, TECMStepName, TECMTEmpCode, TECMWorkDate, TECMStartTime, TECMEndTime, TECMQuantity, TECMCost, TECMTotal, TECMRemark, TECMFlag1, TECMFlag2, TECMFlag3)
		SELECT TECMTEWCNo, TECMLn, TECMTJbMTJobNo, TECMTJbMLn, TECMTSpdStep, TECMTJPdNo, TECMTSepCode, TECMStepName, TECMTEmpCode, TECMWorkDate, CONVERT(datetime, TECMStartTime), CONVERT(datetime, TECMEndTime), TECMQuantity, TECMCost, TECMTotal, TECMRemark, TECMFlag1, TECMFlag2, TECMFlag3 FROM dbo.VS4TEmpWorkCountMB (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.VS4TEmpWorkCountMB
GO
EXECUTE sp_rename N'dbo.Tmp_VS4TEmpWorkCountMB', N'VS4TEmpWorkCountMB', 'OBJECT'
GO
ALTER TABLE dbo.VS4TEmpWorkCountMB ADD CONSTRAINT
	TECMLn PRIMARY KEY CLUSTERED 
	(
	TECMLn,
	TECMTEWCNo
	) ON [PRIMARY]

GO
CREATE NONCLUSTERED INDEX PrimaryKey ON dbo.VS4TEmpWorkCountMB
	(
	TECMLn,
	TECMTEWCNo
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TJDLStepName ON dbo.VS4TEmpWorkCountMB
	(
	TECMStepName
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TJDLTJbMTJobNo ON dbo.VS4TEmpWorkCountMB
	(
	TECMTJbMTJobNo
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TJDLTSepCode ON dbo.VS4TEmpWorkCountMB
	(
	TECMTSepCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX TJDLTSpdStep ON dbo.VS4TEmpWorkCountMB
	(
	TECMTSpdStep
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX VS4TEmployeeVS4TEmpWorkCountMB ON dbo.VS4TEmpWorkCountMB
	(
	TECMTEmpCode
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX VS4TEmpWorkCountVS4TEmpWorkCountMB ON dbo.VS4TEmpWorkCountMB
	(
	TECMTEWCNo
	) ON [PRIMARY]
GO
ALTER TABLE dbo.VS4TEmpWorkCountMB WITH NOCHECK ADD CONSTRAINT
	VS4TEmployeeVS4TEmpWorkCountMB FOREIGN KEY
	(
	TECMTEmpCode
	) REFERENCES dbo.VS4TEmployee
	(
	TEmpCode
	) ON UPDATE CASCADE
	
GO
ALTER TABLE dbo.VS4TEmpWorkCountMB WITH NOCHECK ADD CONSTRAINT
	VS4TEmpWorkCountVS4TEmpWorkCountMB FOREIGN KEY
	(
	TECMTEWCNo
	) REFERENCES dbo.VS4TEmpWorkCount
	(
	TEWCNo
	) ON UPDATE CASCADE
	
GO

