CREATE TABLE [article] (
	[id] [bigint] IDENTITY (1, 1) NOT NULL ,
	[ticket_id] [int] NOT NULL ,
	[article_type_id] [smallint] NOT NULL ,
	[article_sender_type_id] [smallint] NOT NULL ,
	[a_from] [varchar] (255) NULL ,
	[a_reply_to] [varchar] (255) NULL ,
	[a_to] [varchar] (255) NULL ,
	[a_cc] [varchar] (255) NULL ,
	[a_subject] [varchar] (255) NULL ,
	[a_message_id] [varchar] (250) NULL ,
	[a_content_type] [varchar] (250) NULL ,
	[a_body] [varchar] (8000) NOT NULL ,
	[incoming_time] [int] NOT NULL ,
	[content_path] [varchar] (250) NULL ,
	[a_freekey1] [varchar] (250) NULL ,
	[a_freetext1] [varchar] (250) NULL ,
	[a_freekey2] [varchar] (250) NULL ,
	[a_freetext2] [varchar] (250) NULL ,
	[a_freekey3] [varchar] (250) NULL ,
	[a_freetext3] [varchar] (250) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_article] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [article_attachment] (
	[id] [bigint] IDENTITY (1, 1) NOT NULL ,
	[article_id] [bigint] NOT NULL ,
	[filename] [varchar] (250) NULL ,
	[content_type] [varchar] (250) NULL ,
	[content] [image] NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_article_attachment] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

CREATE TABLE [article_plain] (
	[id] [bigint] IDENTITY (1, 1) NOT NULL ,
	[article_id] [bigint] NOT NULL ,
	[body] [text] NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_article_plain] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]


CREATE TABLE [article_sender_type] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (100) NOT NULL ,
	[comment] [varchar] (250) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_article_sender_type] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_article_sender_type] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [article_type] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (100) NOT NULL ,
	[comment] [varchar] (250) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_article_type] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_article_type] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [auto_response] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (80) NOT NULL ,
	[text0] [text] NULL ,
	[text1] [text] NULL ,
	[text2] [text] NULL ,
	[type_id] [smallint] NOT NULL ,
	[system_address_id] [smallint] NOT NULL ,
	[charset_id] [smallint] NOT NULL ,
	[comment] [varchar] (100) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_auto_response] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_auto_response] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

CREATE TABLE [auto_response_type] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (50) NOT NULL ,
	[comment] [varchar] (80) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_auto_response_type] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_auto_response_type] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [charset] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (200) NOT NULL ,
	[charset] [varchar] (50) NOT NULL ,
	[comment] [varchar] (250) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_charset] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_charset] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [customer_preferences] (
	[user_id] [varchar] (250) NOT NULL ,
	[preferences_key] [varchar] (150) NOT NULL ,
	[preferences_value] [varchar] (250) NULL 
) ON [PRIMARY]


CREATE TABLE [customer_user] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[login] [varchar] (100) NOT NULL ,
	[email] [varchar] (150) NOT NULL ,
	[customer_id] [varchar] (200) NOT NULL ,
	[pw] [varchar] (50) NOT NULL ,
	[salutation] [varchar] (50) NULL ,
	[first_name] [varchar] (100) NOT NULL ,
	[last_name] [varchar] (100) NOT NULL ,
	[valid_id] [smallint] NOT NULL ,
	[comment] [varchar] (250) NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	[phone] [varchar] (25) NULL ,
	[mobile] [varchar] (25) NULL ,
	[depart] [varchar] (50) NULL ,
	[location] [varchar] (50) NULL ,
	CONSTRAINT [PK_customer_user] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_customer_user] UNIQUE  NONCLUSTERED 
	(
		[login]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [faq] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (200) NOT NULL ,
	[text] [varchar] (255) NOT NULL ,
	[language_id] [smallint] NOT NULL ,
	[comment] [varchar] (80) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_faq] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [follow_up_possible] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (200) NOT NULL ,
	[comment] [varchar] (200) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_follow_up_possible] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_follow_up_possible] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [group_user] (
	[user_id] [int] NOT NULL ,
	[group_id] [int] NOT NULL ,
	[permission_read] [smallint] NOT NULL ,
	[permission_write] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL 
) ON [PRIMARY]

CREATE TABLE [groups] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (100) NOT NULL ,
	[comment] [varchar] (250) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_groups] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_groups] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [personal_queues] (
	[user_id] [int] NOT NULL ,
	[queue_id] [int] NOT NULL 
) ON [PRIMARY]

CREATE TABLE [pop3_account] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[login] [varchar] (200) NOT NULL ,
	[pw] [varchar] (200) NOT NULL ,
	[host] [varchar] (200) NOT NULL ,
	[queue_id] [int] NOT NULL ,
	[trusted] [smallint] NOT NULL ,
	[comment] [varchar] (250) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_pop3_account] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [queue] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (200) NOT NULL ,
	[group_id] [int] NOT NULL ,
	[unlock_timeout] [int] NULL ,
	[escalation_time] [int] NULL ,
	[system_address_id] [smallint] NOT NULL ,
	[salutation_id] [smallint] NOT NULL ,
	[signature_id] [smallint] NOT NULL ,
	[follow_up_id] [smallint] NOT NULL ,
	[follow_up_lock] [smallint] NOT NULL ,
	[move_notify] [smallint] NOT NULL ,
	[lock_notify] [smallint] NOT NULL ,
	[state_notify] [smallint] NOT NULL ,
	[owner_notify] [smallint] NOT NULL ,
	[comment] [varchar] (200) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_queue] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_queue] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [queue_auto_response] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[queue_id] [int] NOT NULL ,
	[auto_response_id] [int] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_queue_auto_response] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [queue_standard_response] (
	[queue_id] [int] NOT NULL ,
	[standard_response_id] [int] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL 
) ON [PRIMARY]

CREATE TABLE [salutation] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (100) NOT NULL ,
	[text] [text] NOT NULL ,
	[comment] [varchar] (250) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_salutation] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_salutation] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

CREATE TABLE [session] (
	[session_id] [varchar] (120) NOT NULL ,
	[value] [text] NOT NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

CREATE TABLE [signature] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (100) NOT NULL ,
	[text] [text] NOT NULL ,
	[comment] [varchar] (250) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_signature] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_signature] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

CREATE TABLE [standard_attachment] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (150) NOT NULL ,
	[content_type] [varchar] (150) NOT NULL ,
	[content] [text] NOT NULL ,
	[filename] [varchar] (250) NOT NULL ,
	[comment] [varchar] (150) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_standard_attachment] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_standard_attachment] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

CREATE TABLE [standard_response] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (80) NOT NULL ,
	[text] [text] NOT NULL ,
	[comment] [varchar] (80) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_standard_response] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_standard_response] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

CREATE TABLE [standard_response_attachment] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[standard_attachment_id] [int] NOT NULL ,
	[standard_response_id] [int] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_standard_response_attachment] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [sys_user] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[login] [varchar] (100) NOT NULL ,
	[pw] [varchar] (50) NOT NULL ,
	[salutation] [varchar] (50) NULL ,
	[first_name] [varchar] (100) NOT NULL ,
	[last_name] [varchar] (100) NOT NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_sys_user] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_sys_user] UNIQUE  NONCLUSTERED 
	(
		[login]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [system_address] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[value0] [varchar] (200) NOT NULL ,
	[value1] [varchar] (200) NOT NULL ,
	[value2] [varchar] (200) NULL ,
	[value3] [varchar] (200) NULL ,
	[queue_id] [int] NOT NULL ,
	[comment] [varchar] (200) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_system_address] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [theme] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[theme] [varchar] (100) NOT NULL ,
	[valid_id] [smallint] NOT NULL CONSTRAINT [DF_theme_valid_id] DEFAULT (0),
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL CONSTRAINT [DF_theme_create_by] DEFAULT (0),
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL CONSTRAINT [DF_theme_change_by] DEFAULT (0),
	CONSTRAINT [PK_theme] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_theme] UNIQUE  NONCLUSTERED 
	(
		[theme]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [ticket] (
	[id] [bigint] IDENTITY (1, 1) NOT NULL ,
	[tn] [varchar] (50) NOT NULL ,
	[queue_id] [int] NOT NULL ,
	[ticket_lock_id] [smallint] NOT NULL ,
	[ticket_answered] [smallint] NOT NULL ,
	[user_id] [int] NOT NULL ,
	[group_id] [int] NOT NULL ,
	[ticket_priority_id] [smallint] NOT NULL ,
	[ticket_state_id] [smallint] NOT NULL ,
	[group_read] [smallint] NULL ,
	[group_write] [smallint] NULL ,
	[other_read] [smallint] NULL ,
	[other_write] [smallint] NULL ,
	[customer_id] [varchar] (150) NULL ,
	[customer_user_id] [varchar] (250) NULL ,
	[timeout] [int] NULL ,
	[until_time] [int] NULL ,
	[freekey1] [varchar] (150) NULL ,
	[freetext1] [varchar] (150) NULL ,
	[freekey2] [varchar] (150) NULL ,
	[freetext2] [varchar] (150) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time_unix] [int] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_ticket] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_ticket] UNIQUE  NONCLUSTERED 
	(
		[tn]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [ticket_history] (
	[id] [bigint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (250) NOT NULL ,
	[history_type_id] [smallint] NOT NULL ,
	[ticket_id] [bigint] NOT NULL ,
	[article_id] [bigint] NULL ,
	[system_queue_id] [smallint] NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_ticket_history] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [ticket_history_type] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (100) NOT NULL ,
	[comment] [varchar] (250) NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_ticket_history_type] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_ticket_history_type] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [ticket_index] (
	[ticket_id] [bigint] NOT NULL ,
	[queue_id] [int] NOT NULL ,
	[queue] [varchar] (70) NOT NULL ,
	[group_id] [int] NOT NULL ,
	[s_lock] [varchar] (70) NOT NULL ,
	[s_state] [varchar] (70) NOT NULL ,
	[create_time_unix] [bigint] NOT NULL 
) ON [PRIMARY]

CREATE TABLE [ticket_lock_index] (
	[ticket_id] [bigint] NOT NULL 
) ON [PRIMARY]

CREATE TABLE [ticket_lock_type] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (50) NOT NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_ticket_lock_type] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_ticket_lock_type] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [ticket_loop_protection] (
	[sent_to] [varchar] (250) NOT NULL ,
	[sent_date] [varchar] (150) NOT NULL 
) ON [PRIMARY]

CREATE TABLE [ticket_priority] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (50) NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_ticket_priority] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_ticket_priority] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [ticket_state] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (200) NOT NULL ,
	[comment] [varchar] (250) NULL ,
	[type_id] [smallint] NOT NULL ,
	[valid_id] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_ticket_state] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_ticket_state] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [ticket_state_type] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (120) NOT NULL ,
	[comment] [varchar] (250) NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_ticket_state_type] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_ticket_state_type] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [time_accounting] (
	[id] [bigint] IDENTITY (1, 1) NOT NULL ,
	[ticket_id] [bigint] NOT NULL ,
	[article_id] [bigint] NULL ,
	[time_unit] [smallint] NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_time_accounting] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
) ON [PRIMARY]

CREATE TABLE [user_preferences] (
	[user_id] [int] NOT NULL ,
	[preferences_key] [varchar] (150) NOT NULL ,
	[preferences_value] [varchar] (250) NULL 
) ON [PRIMARY]

CREATE TABLE [valid] (
	[id] [smallint] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (50) NOT NULL ,
	[create_time] [smalldatetime] NOT NULL ,
	[create_by] [int] NOT NULL ,
	[change_time] [smalldatetime] NOT NULL ,
	[change_by] [int] NOT NULL ,
	CONSTRAINT [PK_valid] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_valid] UNIQUE  NONCLUSTERED 
	(
		[name]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO
