
DROP TABLE [dbo].[OM_WorkOrderStatusRecLst]
CREATE TABLE [dbo].[OM_WorkOrderStatusRecLst] (
[PlantNr] int NOT NULL ,
[WorkOrderId] nvarchar(40) NOT NULL ,
[Pos] int NOT NULL ,
[PrevStatus] int NOT NULL ,
[Status] int NOT NULL ,
[StartTime] datetime NULL ,
[EndTime] datetime NULL ,
[TriggerEvent] nvarchar(40) NOT NULL ,
[TriggerObjectId] nvarchar(40) NOT NULL ,
[TriggerSubObjectId] nvarchar(40) NOT NULL ,
[OutputStatus] int NOT NULL ,
[OutputEvent] nvarchar(40) NOT NULL ,
[OutputEventMessageId] nvarchar(40) NOT NULL ,
[OutputObjectId] nvarchar(40) NOT NULL ,
[OutputSubObjectId] nvarchar(40) NOT NULL ,
[Remark1] nvarchar(100) NOT NULL ,
[Remark2] nvarchar(100) NOT NULL ,
[LastModify] datetime NOT NULL ,
[LastUser] nvarchar(20) NOT NULL ,
[CreateTime] datetime NOT NULL 
)


IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'OM_WorkOrderStatusRecLst', 
'COLUMN', N'Pos')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'yao'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'OM_WorkOrderStatusRecLst'
, @level2type = 'COLUMN', @level2name = N'Pos'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'yao'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'OM_WorkOrderStatusRecLst'
, @level2type = 'COLUMN', @level2name = N'Pos'
IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'OM_WorkOrderStatusRecLst', 
'COLUMN', N'PrevStatus')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'yao'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'OM_WorkOrderStatusRecLst'
, @level2type = 'COLUMN', @level2name = N'PrevStatus'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'yao'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'OM_WorkOrderStatusRecLst'
, @level2type = 'COLUMN', @level2name = N'PrevStatus'
IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 
'SCHEMA', N'dbo', 
'TABLE', N'OM_WorkOrderStatusRecLst', 
'COLUMN', N'Status')) > 0) 
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'yao'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'OM_WorkOrderStatusRecLst'
, @level2type = 'COLUMN', @level2name = N'Status'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'yao'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'OM_WorkOrderStatusRecLst'
, @level2type = 'COLUMN', @level2name = N'Status'


ALTER TABLE [dbo].[OM_WorkOrderStatusRecLst] ADD PRIMARY KEY ([PlantNr], [WorkOrderId], [Pos])
