IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_csttype]') AND type = 'U')
CREATE TABLE [dbo].[mps_csttype]
(
    [ct_id] int NOT NULL IDENTITY(1, 1),
    [ct_cmpid] int NULL DEFAULT((0)),
    [ct_tag] int NULL DEFAULT((1)),
    [ct_caption] nvarchar(50) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''),
    [ct_type] nvarchar(50) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''),
    [ct_icon] varchar(200) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''),
    [ct_database] varchar(50) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''),
    [ct_groupfields] varchar(500) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''),
    [ct_bmcode] varchar(200) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''),
    [ct_status] int NULL DEFAULT((1)),
    [ct_security] int NULL DEFAULT((0)),
    [ct_changed] int NULL,
    [ct_querytime] int NULL DEFAULT((0)),
    [ct_searchfields] varchar(2000) COLLATE Chinese_PRC_CI_AS NULL,
    [ct_selectfuncs] nvarchar(500) COLLATE Chinese_PRC_CI_AS NULL,
    [ct_selectstyle] int NULL DEFAULT((0)),
    [ct_order] int NULL,
    [ct_select] nvarchar(4000) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''),
    [ct_from] nvarchar(2000) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''),
    [ct_where] nvarchar(4000) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''),
    [ct_orderby] nvarchar(2000) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''),
    [ct_funcs] varchar(200) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''),
    [ct_flows] nvarchar(2000) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''),
    [ct_params] varchar(500) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''),
    [ct_viewscope] int NULL DEFAULT((0)),
    [ct_views] int NULL DEFAULT((0)),
    [ct_allowlogin] int NULL DEFAULT((1)),
    [ct_loginscope] varchar(150) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''),
    CONSTRAINT [PK_MPS_CSTTYPE] PRIMARY KEY ([ct_id] ASC)
)

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[dbo].[mps_csttype]') AND name = 'mps_csttype_index')
CREATE NONCLUSTERED INDEX [mps_csttype_index] ON [dbo].[mps_csttype]([ct_cmpid] ASC)