IF NOT EXISTS (SELECT 1 FROM sysobjects WHERE name = 'PREPARETABLENAME')
BEGIN
    CREATE TABLE [dbo].[PREPARETABLENAME] (
        [id] INT IDENTITY NOT NULL,
        [prodsubtype] CHAR(10) NOT NULL,
        [resprodcode] VARCHAR(13) NOT NULL,
        [code20] CHAR(20) NOT NULL,
        [parentcode] CHAR(20),
        [codelv] TINYINT NOT NULL,
        [lv4code] TINYINT DEFAULT 0 NOT NULL,
        [lv3code] TINYINT DEFAULT 0 NOT NULL,
        [lv2code] TINYINT DEFAULT 0 NOT NULL,
        [lv1code] TINYINT DEFAULT 0 NOT NULL,
        [smidcode] CHAR(20),
        [lmidcode] CHAR(20),
        [boxcode] CHAR(20) NOT NULL,
        [codeflag] TINYINT NOT NULL,
        [lineid] CHAR(4) NOT NULL,
        [taskid] INT NOT NULL,
        [status] TINYINT NOT NULL DEFAULT 0,
        [sysuserid] INT DEFAULT -1,
        [savetime] DATETIME DEFAULT GETDATE() NOT NULL,
        [updateuser] INT,
        [updatetime] DATETIME,
        PRIMARY KEY NONCLUSTERED ([code20])
    );

    CREATE CLUSTERED INDEX [IX_PREPARETABLENAME_pkk] ON [dbo].[PREPARETABLENAME] ([taskid] ASC, [boxcode] ASC, [codelv] DESC) WITH (
        PAD_INDEX = OFF,
        STATISTICS_NORECOMPUTE = OFF,
        SORT_IN_TEMPDB = OFF,
        IGNORE_DUP_KEY = OFF,
        DROP_EXISTING = OFF,
        ONLINE = OFF,
        ALLOW_ROW_LOCKS = ON,
        ALLOW_PAGE_LOCKS = ON
    ) ON [PRIMARY];

    CREATE NONCLUSTERED INDEX [IX_PREPARETABLENAME_1] ON [dbo].[PREPARETABLENAME] ([boxcode] ASC) WITH (
        PAD_INDEX = OFF,
        STATISTICS_NORECOMPUTE = OFF,
        SORT_IN_TEMPDB = OFF,
        IGNORE_DUP_KEY = OFF,
        DROP_EXISTING = OFF,
        ONLINE = OFF,
        ALLOW_ROW_LOCKS = ON,
        ALLOW_PAGE_LOCKS = ON
    ) ON [PRIMARY];

    CREATE NONCLUSTERED INDEX [IX_PREPARETABLENAME_2] ON [dbo].[PREPARETABLENAME] ([smidcode] ASC) WITH (
        PAD_INDEX = OFF,
        STATISTICS_NORECOMPUTE = OFF,
        SORT_IN_TEMPDB = OFF,
        IGNORE_DUP_KEY = OFF,
        DROP_EXISTING = OFF,
        ONLINE = OFF,
        ALLOW_ROW_LOCKS = ON,
        ALLOW_PAGE_LOCKS = ON
    ) ON [PRIMARY];
END;