IF EXISTS  (SELECT * FROM sysobjects WHERE name='APP_LAST_UPDATES')
DROP TABLE APP_LAST_UPDATES

IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='APP_LAST_UPDATES')
CREATE TABLE [dbo].[APP_LAST_UPDATES](
[ID] [int] PRIMARY KEY IDENTITY(1,1) NOT NULL,
[tablename] [varchar](255) NULL,
[lastUpdate] [datetime] NOT NULL DEFAULT GETDATE()
)


/****** Object:  Table [dbo].[CSAPP_Appointments]    Script Date: 07.03.2019 13:32:27 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_Appointments')
CREATE TABLE [dbo].[CSAPP_Appointments](
[PK] [int] IDENTITY(1,1) NOT NULL,
[Kunde] [int] NULL,
[MVANUMMER] [varchar](12) NULL,
[Start] [datetime] NULL,
[Ende] [datetime] NULL,
[Standort] [varchar](50) NULL,
[Beschreibung] [varchar](max) NULL,
[Werkstatt] [bit] NULL,
[Logistik] [bit] NULL,
[Auftragsnummer] [varchar](50) NULL,
[Station] [varchar](255) NULL,
 CONSTRAINT [PK__CSAPP_Ap__3215078704B60D13] PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_CAMERA_VIEWS]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_CAMERA_VIEWS')
CREATE TABLE [dbo].[CSAPP_CAMERA_VIEWS](
[PK] [int] NOT NULL,
[TEXT] [varchar](30) NOT NULL,
[VIEWTYPE] [varchar](255) NULL,
[IMAGES] [varchar](50) NULL,
[MARKABLE] [bit] NULL
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_CHECKLISTS]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_CHECKLISTS')
CREATE TABLE [dbo].[CSAPP_CHECKLISTS](
[ID] [int] NOT NULL,
[GROUP] [int] NOT NULL,
[TEXT] [varchar](255) NULL,
[CI] [bit] NULL,
[CO] [bit] NULL,
[Obligatorisch] [bit] NULL
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_CHECKLISTS_REL_MV]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_CHECKLISTS_REL_MV')
CREATE TABLE [dbo].[CSAPP_CHECKLISTS_REL_MV](
[ID] [int] NOT NULL,
[VERTRAGSNUMMER] [int] NOT NULL,
[GROUP] [varchar](30) NOT NULL,
[TEXT] [varchar](255) NULL,
[CI] [bit] NULL,
[CO] [bit] NULL,
[Obligatorisch] [bit] NULL,
[STATUS] [bit] NULL
) ON [PRIMARY]

/****** Object:  Table [dbo].[csapp_damagetypes]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='csapp_damagetypes')
CREATE TABLE [dbo].[csapp_damagetypes](
[Name] [varchar](255) NULL,
[PK] [int] IDENTITY(1,1) NOT NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


/****** Object:  Table [dbo].[CSAPP_DAMGEPICTURE_REL_PROTOCOL]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_DAMGEPICTURE_REL_PROTOCOL')
CREATE TABLE [dbo].[CSAPP_DAMGEPICTURE_REL_PROTOCOL](
[PK] [int] IDENTITY(1,1) NOT NULL,
[PROTOKOLL_PK] [int] NOT NULL,
[CAMERAVIEW_PK] [int] NULL,
[BILD_PK] [int] NULL,
[SCHADEN_PK] [int] NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_IMAGES]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_IMAGES')
CREATE TABLE [dbo].[CSAPP_IMAGES](
[PK] [int] NOT NULL,
[Key] [varchar](255) NOT NULL,
[Data] [image] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_INVENTORY]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_INVENTORY')
CREATE TABLE [dbo].[CSAPP_INVENTORY](
[PK] [int] IDENTITY(1,1) NOT NULL,
[PK_INVENTORY] [int] NULL,
[GROUP] [varchar](10) NULL,
[TYPE] [varchar](30) NULL,
[MANDATORY] [bit] NULL,
[SORT] [int] NULL,
[DESCRIPTION] [varchar](255) NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_INVENTORY_REL_PROTOCOL]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_INVENTORY_REL_PROTOCOL')
CREATE TABLE [dbo].[CSAPP_INVENTORY_REL_PROTOCOL](
[PK] [int] IDENTITY(1,1) NOT NULL,
[PK_PROTOKOLL] [int] NULL,
[PK_INVENTAR] [int] NULL,
[VALUE] [int] NULL,
[COMMENT] [varchar](255) NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_INVERS_IMMOBILIZER_CHANGED_EVENTS]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_INVERS_IMMOBILIZER_CHANGED_EVENTS')
CREATE TABLE [dbo].[CSAPP_INVERS_IMMOBILIZER_CHANGED_EVENTS](
[sequence_no] [varchar](50) NOT NULL,
[qnr] [varchar](50) NULL,
[eventTimestamp] [datetime] NULL,
[positionLon] [float] NULL,
[positionAlt] [float] NULL,
[statusImmobilizer] [varchar](10) NULL,
[mileage] [int] NULL,
[fuel] [int] NULL,
[bluetoothKeyUuid] [varchar](255) NULL,
[Reservation] [int] NULL
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_KUNDEN_LOG]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_KUNDEN_LOG')
CREATE TABLE [dbo].[CSAPP_KUNDEN_LOG](
[ID] [int] IDENTITY(1,1) NOT NULL,
[DATUM] [datetime] NOT NULL,
[TEXT] [varchar](2000) NULL,
[DEVICE] [varchar](255) NULL,
[OS] [varchar](255) NULL,
[OS_VERSION] [varchar](255) NULL,
[APP_VERSION] [varchar](255) NULL,
[ERROR_CODE] [int] NULL,
[ERROR_MESSAGE] [varchar](255) NULL,
[API_ERROR_CODE] [varchar](255) NULL,
[KUNDENNUMMER] [int] NULL
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_KUNDEN_LOGS]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_KUNDEN_LOGS')
CREATE TABLE [dbo].[CSAPP_KUNDEN_LOGS](
[ID] [int] IDENTITY(1,1) NOT NULL,
[TAG] [varchar](255) NULL,
[LOG_MESSAGE] [varchar](255) NULL,
[LOG_TIMESTAMP] [datetime] NULL,
[LOG_ID] [int] NOT NULL,
[LOG_LEVEL] [varchar](255) NULL,
PRIMARY KEY CLUSTERED 
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_NEWS]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_NEWS')
CREATE TABLE [dbo].[CSAPP_NEWS](
[PK] [int] IDENTITY(1,1) NOT NULL,
[news_date] [datetime] NULL,
[title] [varchar](255) NULL,
[text] [varchar](max) NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

/***** Object:  Table [dbo].[CSAPP_OPENCLOSE_LOG]    Script Date: 07.03.2019 13:32:28 *****/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_OPENCLOSE_LOG')
CREATE TABLE [dbo].[CSAPP_OPENCLOSE_LOG](
[PK] [int] IDENTITY(1,1) NOT NULL,
[source] [varchar](255) NULL,
[reservation] [varchar](255) NULL,
[crentuser] [varchar](255) NULL,
[customer] [int] NULL,
[qnr] [varchar](255) NULL,
[openVehicle] [bit] NULL,
[coci] [bit] NULL,
[timestamp] [datetime] NULL,
[success] [bit] NULL,
[errorMessage] [varchar](255) NULL,
[stateImmobilizer] [varchar](255) NULL,
[stateCentralLock] [varchar](255) NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_OPTIONS_FIELDS]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_OPTIONS_FIELDS')
CREATE TABLE [dbo].[CSAPP_OPTIONS_FIELDS](
[PK] [int] IDENTITY(1,1) NOT NULL,
[PROTOKOLL_PK] [int] NOT NULL,
[OPTIONS_NAME] [varchar](255) NULL,
[OPTIONS_VALUE] [bit] NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_PROTOCOL]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_PROTOCOL')
CREATE TABLE [dbo].[CSAPP_PROTOCOL](
[PK] [int] IDENTITY(1,1) NOT NULL,
[PROTOCOL_PK] [int] NOT NULL,
[FIELD_NAME] [varchar](100) NULL,
[FIELD_VALUE] [varchar](100) NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_PROTOCOL_GROUPS]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_PROTOCOL_GROUPS')
CREATE TABLE [dbo].[CSAPP_PROTOCOL_GROUPS](
[PK] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](255) NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_PROTOCOL_GROUPS_REL_TYPES]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_PROTOCOL_GROUPS_REL_TYPES')
CREATE TABLE [dbo].[CSAPP_PROTOCOL_GROUPS_REL_TYPES](
[group] [int] NULL,
[type] [int] NULL,
[PK] [int] IDENTITY(1,1) NOT NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_PROTOCOL_OPTIONS]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_PROTOCOL_OPTIONS')
CREATE TABLE [dbo].[CSAPP_PROTOCOL_OPTIONS](
[PK] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](255) NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_PROTOCOL_TYPES]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_PROTOCOL_TYPES')
CREATE TABLE [dbo].[CSAPP_PROTOCOL_TYPES](
[PK] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](255) NULL,
[mail] [varchar](255) NULL,
[saveDamageReport] [bit] NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_PROTOCOL_TYPES_REL_MAIL]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_PROTOCOL_TYPES_REL_MAIL')
CREATE TABLE [dbo].[CSAPP_PROTOCOL_TYPES_REL_MAIL](
[PK] [int] IDENTITY(1,1) NOT NULL,
[PROTOCOL_TYPE_PK] [int] NOT NULL,
[MAIL] [varchar](255) NULL
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_PROTOCOL_TYPES_REL_OPTIONS]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_PROTOCOL_TYPES_REL_OPTIONS')
CREATE TABLE [dbo].[CSAPP_PROTOCOL_TYPES_REL_OPTIONS](
[option] [int] NULL,
[type] [int] NULL,
[PK] [int] IDENTITY(1,1) NOT NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_PROTOCOLTYPE]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_PROTOCOLTYPE')
CREATE TABLE [dbo].[CSAPP_PROTOCOLTYPE](
[ID] [int] NOT NULL,
[NAME] [varchar](255) NULL
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_STATION_REL_GRUPPE]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_STATION_REL_GRUPPE')
CREATE TABLE [dbo].[CSAPP_STATION_REL_GRUPPE](
[PK] [int] NOT NULL,
[Station] [varchar](30) NULL,
[Gruppe] [varchar](30) NULL
) ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_SUPPORT_MAIL]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_SUPPORT_MAIL')
CREATE TABLE [dbo].[CSAPP_SUPPORT_MAIL](
[PK] [int] IDENTITY(1,1) NOT NULL,
[MAILTEXT] [varchar](max) NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

/****** Object:  Table [dbo].[CSAPP_ZUSTANDSBILDER_REL_PROTOKOLL]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_ZUSTANDSBILDER_REL_PROTOKOLL')
CREATE TABLE [dbo].[CSAPP_ZUSTANDSBILDER_REL_PROTOKOLL](
[PK] [int] IDENTITY(1,1) NOT NULL,
[PROTOKOLL_PK] [int] NOT NULL,
[CAMERAVIEW_PK] [int] NULL,
[BILD_PK] [int] NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[CUSTOMER_REL_IMEI]    Script Date: 07.03.2019 13:32:28 ******/
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CUSTOMER_REL_IMEI')
CREATE TABLE [dbo].[CUSTOMER_REL_IMEI](
[PK] [int] IDENTITY(1,1) NOT NULL,
[PKCUSTOMER] [varchar](255) NOT NULL,
[IMEI] [varchar](255) NULL,
PRIMARY KEY CLUSTERED 
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_API_UPDATE')
create table CSAPP_API_UPDATE
(
PK INT PRIMARY KEY IDENTITY(1,1) NOT NULL,
LAST_UPDATE DATETIME NOT NULL
)

IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CSAPP_INTERESTED_PERSON')
create table CSAPP_INTERESTED_PERSON
(
PK INT PRIMARY KEY IDENTITY(1,1) NOT NULL,
[SALUTATION] [varchar](255)  NULL,
[FIRSTNAME] [varchar](255)  NULL,
[LASTNAME] [varchar](255)  NULL,
[MAIL] [varchar](255)  NULL,
[RECORDDATE] [datetime]  NULL,
)

