IF OBJECT_ID(N'[dbo].[Hr_T_AttendanceLog]', 'U') IS NULL BEGIN CREATE TABLE [dbo].[Hr_T_AttendanceLog] ( [Id] uniqueidentifier NOT NULL DEFAULT NEWID(), [TenantId] uniqueidentifier NULL, [EmployeeId] uniqueidentifier NULL, [CardNo] nvarchar(64) NULL, [EventTime] datetime2 NOT NULL, [Direction] nvarchar(8) NOT NULL DEFAULT N'Auto', [Source] nvarchar(16) NULL, [DeviceCode] nvarchar(64) NULL, [Note] nvarchar(512) NULL, [WorkDate] date NULL, [IsProcessed] bit NOT NULL DEFAULT 0, [ProcessError] nvarchar(32) NULL, [CreationTime] datetime2 NOT NULL DEFAULT GETUTCDATE(), [CreatorId] uniqueidentifier NULL, [LastModificationTime] datetime2 NULL, [LastModifierId] uniqueidentifier NULL, [IsDeleted] bit NOT NULL DEFAULT 0, [DeletionTime] datetime2 NULL, [DeleterId] uniqueidentifier NULL, CONSTRAINT [PK_Hr_T_AttendanceLog] PRIMARY KEY NONCLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] END GO IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'IX_Hr_T_AttendanceLog_Employee' AND object_id = OBJECT_ID(N'[dbo].[Hr_T_AttendanceLog]')) CREATE INDEX [IX_Hr_T_AttendanceLog_Employee] ON [dbo].[Hr_T_AttendanceLog] ([EmployeeId], [WorkDate]) INCLUDE ([EventTime], [Direction], [IsDeleted], [ProcessError]) GO IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'IX_Hr_T_AttendanceLog_Pending' AND object_id = OBJECT_ID(N'[dbo].[Hr_T_AttendanceLog]')) CREATE INDEX [IX_Hr_T_AttendanceLog_Pending] ON [dbo].[Hr_T_AttendanceLog] ([IsProcessed]) WHERE [IsProcessed] = 0 GO