IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Import' AND schema_id = SCHEMA_ID('dbo'))
BEGIN
	CREATE TABLE [dbo].[Import](
		[GUID] [uniqueidentifier] NOT NULL,
		[PatientId] [varchar](64) NULL,
		[AccNo] [varchar](64) NULL,
		[FileType] [varchar](32) NULL,
		[FilePath] [varchar](max) NULL,
		[State] [int] NULL,
		[InsertTime] [datetime] NULL
	 CONSTRAINT [PK_Import] PRIMARY KEY CLUSTERED 
	(
		[GUID] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
	) ON [PRIMARY]
END

--GO


IF NOT EXISTS (
    SELECT * FROM sys.default_constraints WHERE name = 'DF_Import_GUID'
)
BEGIN
	ALTER TABLE [dbo].[Import] ADD  CONSTRAINT [DF_Import_GUID]  DEFAULT (newid()) FOR [GUID]
END

--GO

IF NOT EXISTS (
    SELECT * FROM sys.default_constraints WHERE name = 'DF_Import_State'
)
BEGIN
	ALTER TABLE [dbo].[Import] ADD  CONSTRAINT [DF_Import_State]  DEFAULT ((0)) FOR [State]
END

--GO

IF NOT EXISTS (
    SELECT * FROM sys.default_constraints WHERE name = 'DF_Import_InsertTime'
)
BEGIN
	ALTER TABLE [dbo].[Import] ADD  CONSTRAINT [DF_Import_InsertTime]  DEFAULT (getdate()) FOR [InsertTime]
END

--GO

IF NOT EXISTS (
    SELECT * FROM sys.indexes WHERE name = 'IX_Import_PatientId' AND object_id = OBJECT_ID('dbo.Import')
)
BEGIN

	CREATE NONCLUSTERED INDEX IX_Import_PatientId ON dbo.Import
		(
		PatientId
		) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END

--GO

IF NOT EXISTS (
    SELECT * FROM sys.indexes WHERE name = 'IX_Import_AccNo' AND object_id = OBJECT_ID('dbo.Import')
)
BEGIN
	CREATE NONCLUSTERED INDEX IX_Import_AccNo ON dbo.Import
		(
		AccNo
		) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
--GO
