-- DROP SCHEMA dbo;

CREATE SCHEMA dbo;

-- TESISSEG.dbo.AS_AGENDA definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_AGENDA;

CREATE TABLE TESISSEG.dbo.AS_AGENDA (
	AGN_ID int IDENTITY(1,1) NOT NULL,
	AGN_Fecha datetime NULL,
	AGN_Hora varchar(5) COLLATE Modern_Spanish_CI_AS NULL,
	AGN_Situacion smallint NULL,
	AGN_UsuarioDestino int NULL,
	AGN_Prioridad smallint NULL,
	AGN_TipoObjeto smallint NULL,
	AGN_ObjetoID int NULL,
	USR_Id_FC int NULL,
	USR_Id_FM int NULL,
	AGN_FC datetime NOT NULL,
	AGN_FM datetime NOT NULL,
	AGN_Descripcion varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	AGN_AliasObjeto varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	TRP_ID int NULL,
	AGN_PeticionId varchar(15) COLLATE Modern_Spanish_CI_AS NULL,
	AGN_UsuarioDestinoTesis char(5) COLLATE Modern_Spanish_CI_AS NULL,
	USR_Id_FCTesis char(5) COLLATE Modern_Spanish_CI_AS NULL,
	USR_Id_FMTesis char(5) COLLATE Modern_Spanish_CI_AS NULL,
	AGN_ObjetoIDTesis char(30) COLLATE Modern_Spanish_CI_AS NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_AGENDA PRIMARY KEY (AGN_ID)
);


-- TESISSEG.dbo.AS_AGENDA_USUARIOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_AGENDA_USUARIOS;

CREATE TABLE TESISSEG.dbo.AS_AGENDA_USUARIOS (
	AGN_ID int IDENTITY(1,1) NOT NULL,
	AGN_Fecha datetime NULL,
	AGN_Hora varchar(5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	AGN_Situacion smallint NULL,
	AGN_UsuarioDestino int NULL,
	AGN_Prioridad smallint NULL,
	AGN_TipoObjeto smallint NULL,
	AGN_ObjetoID varchar(30) COLLATE Modern_Spanish_CI_AS NULL,
	USR_Id_FC int NOT NULL,
	USR_Id_FM int NOT NULL,
	AGN_FC datetime NOT NULL,
	AGN_FM datetime NOT NULL,
	AGN_Descripcion varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	AGN_AliasObjeto varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_AGENDA_USUARIOS PRIMARY KEY (AGN_ID)
);
 CREATE NONCLUSTERED INDEX IND_AGN_Objeto ON TESISSEG.dbo.AS_AGENDA_USUARIOS (  AGN_TipoObjeto ASC  , AGN_ObjetoID ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;
 CREATE NONCLUSTERED INDEX IND_FC_USRFC_OBJID_TIPOOBJ ON TESISSEG.dbo.AS_AGENDA_USUARIOS (  AGN_FC ASC  , USR_Id_FC ASC  , AGN_ObjetoID ASC  , AGN_TipoObjeto ASC  , AGN_ID DESC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;
 CREATE NONCLUSTERED INDEX IND_SITUACION_FECHA ON TESISSEG.dbo.AS_AGENDA_USUARIOS (  AGN_Situacion ASC  , AGN_Fecha ASC  , AGN_ID ASC  , AGN_Hora ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;
CREATE NONCLUSTERED INDEX IND_EmpID ON TESISSEG.dbo.AS_AGENDA_USUARIOS (  EmpID ASC )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;
CREATE NONCLUSTERED INDEX IND_AGN_ObjetoEmp ON TESISSEG.dbo.AS_AGENDA_USUARIOS (  AGN_TipoObjeto ASC  , AGN_ObjetoID ASC , EmpID ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;


-- TESISSEG.dbo.AS_ARCHIVODOCUMENTAL definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_ARCHIVODOCUMENTAL;

CREATE TABLE TESISSEG.dbo.AS_ARCHIVODOCUMENTAL (
	ADC_Id int IDENTITY(1,1) NOT NULL,
	ADC_Objeto smallint NOT NULL,
	OBJ_Id int NOT NULL,
	ADC_Nombre varchar(255) COLLATE Modern_Spanish_CI_AS NOT NULL,
	ADC_Path varchar(255) COLLATE Modern_Spanish_CI_AS NOT NULL,
	ADC_CompName varchar(16) COLLATE Modern_Spanish_CI_AS NULL,
	ADC_FC datetime NULL,
	ADC_ID_FC int NULL,
	ADC_FM datetime NULL,
	ADC_ID_FM int NULL,
	ADC_Observaciones text COLLATE Modern_Spanish_CI_AS NULL,
	ADC_Tipo int NULL,
	ADC_Caducidad datetime NULL,
	ADC_Publicable tinyint DEFAULT 0 NULL,
	ADC_IsFolder tinyint NULL,
	ADC_Folder int NULL,
	ADC_PublicableCli tinyint NULL,
	ADC_Alias varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	ADC_REFERENCIA varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	ADC_GUID varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_ADCDoc PRIMARY KEY (ADC_Id)
);


-- TESISSEG.dbo.AS_AVISOS_CLIENTES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_AVISOS_CLIENTES;

CREATE TABLE TESISSEG.dbo.AS_AVISOS_CLIENTES (
	ACLI_Id int IDENTITY(1,1) NOT NULL,
	ACLI_TipoObj int NOT NULL,
	ACLI_ObjId int NOT NULL,
	ACLI_CliId int NOT NULL,
	ACLI_Fecha datetime NOT NULL,
	ACLI_Asunto varchar(150) COLLATE Modern_Spanish_CI_AS NOT NULL,
	ACLI_Texto text COLLATE Modern_Spanish_CI_AS NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_AVISOS_CLIENTES PRIMARY KEY (ACLI_Id)
);


-- TESISSEG.dbo.AS_CALIFICACIONES_COLABORADORES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CALIFICACIONES_COLABORADORES;

CREATE TABLE TESISSEG.dbo.AS_CALIFICACIONES_COLABORADORES (
	CALCOL_Id int IDENTITY(1,1) NOT NULL,
	CALCOL_Descripcion varchar(MAX) COLLATE Modern_Spanish_CI_AS NULL,
	CALCOL_Puntos int DEFAULT 0 NOT NULL,
	CALCOL_Alias int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_CALIFICACIONES_COLABORADORES PRIMARY KEY (CALCOL_Id)
);


-- TESISSEG.dbo.AS_CAMBIOMEDIACION definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CAMBIOMEDIACION;

CREATE TABLE TESISSEG.dbo.AS_CAMBIOMEDIACION (
	CMD_Id int IDENTITY(1,1) NOT NULL,
	CMD_Cia int NULL,
	CMD_Tomador varchar(MAX) COLLATE Modern_Spanish_CI_AS NULL,
	CMD_NumPoliza varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	CMD_Vencimiento datetime NULL,
	CMD_FechaPeticion datetime NULL,
	CMD_Colaborador int NULL,
	CMD_Estado int DEFAULT 1 NULL,
	CMD_OfiCode int NULL,
	CMD_CartaEnviada int NULL,
	CMD_DniEnviado int NULL,
	CMD_CartaDocId INT NULL,
    CMD_DniDocId INT NULL,
    CMD_CifDocId INT NULL,
    CMD_AutorizacionDocId INT NULL,
	CMD_Cif varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	CMD_Cliente int NULL,
	CMD_AutorizacionEnviada int NULL,
	CMD_Tramitador int NULL,
	ETO_ID int NULL,
	CMD_OldNumPoliza varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	CMD_Comunidades int NULL,
	CMD_Riesgo varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	CMD_Ramo int NULL,
	CMD_CifEnviado int NULL,
	CMD_Deleted tinyint DEFAULT 0 NOT NULL,
	CMD_ColaboradorTesis char(5) COLLATE Modern_Spanish_CI_AI NULL,
	CMD_CiaTesis char(5) COLLATE Modern_Spanish_CI_AI NULL,
	CMD_RamoTesis char(5) COLLATE Modern_Spanish_CI_AI NULL,
	CMD_TramitadorTesis smallint NULL,
	CMD_ClienteTesis int NULL,
	OldID int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PK_CAMBIOMEDIACION PRIMARY KEY (CMD_Id)
);


-- TESISSEG.dbo.AS_CAMPOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CAMPOS;

CREATE TABLE TESISSEG.dbo.AS_CAMPOS (
	CAMP_Id int IDENTITY(1,1) NOT NULL,
	CAMP_Nombre varchar(100) COLLATE Modern_Spanish_CI_AS NOT NULL,
	CAMP_TipoDato varchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	CAMP_Depende int NULL,
	CAMP_Validaciones text COLLATE Modern_Spanish_CI_AS NULL,
	CAMP_ColumnasDiseno int DEFAULT 2 NOT NULL,
	CAMP_Descripcion varchar(100) COLLATE Modern_Spanish_CI_AS DEFAULT ' ' NOT NULL,
	CAMP_Pdf tinyint DEFAULT 1 NOT NULL,
	CAMP_Offset int DEFAULT 0 NOT NULL,
	CAMP_Orden int DEFAULT 0 NOT NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_CAMPOS PRIMARY KEY (CAMP_Id)
);




-- TESISSEG.dbo.AS_CLIENTES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CLIENTES;

CREATE TABLE TESISSEG.dbo.AS_CLIENTES (
	Id int IDENTITY(1,1) NOT NULL,
	CLI_Id int NULL,
	CLI_Email varchar(60) COLLATE Modern_Spanish_CI_AS NULL,
	CLI_PassApp varchar(64) COLLATE Modern_Spanish_CI_AS NULL,
	CLI_CambiarPass tinyint DEFAULT 0 NOT NULL,
	CLI_VerRelaciones tinyint DEFAULT 0 NOT NULL,
	GDPR datetime NULL,
	CLI_AltaApp datetime NULL,
	CLI_AltaWeb datetime NULL,
	CLI_AccesoApp datetime NULL,
	CLI_AccesoWeb datetime NULL,
	CLI_Anulado tinyint DEFAULT 0 NOT NULL,
	CLI_ContadorApp int DEFAULT 0 NOT NULL,
	CLI_ContadorWeb int DEFAULT 0 NOT NULL,
	CLI_IdTesis int NULL,
	CLI_PersContactoNombre varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	CLI_PersContactoApell1 varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	CLI_PersContactoApell2 varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	CLI_DiaPago smallint NULL,
	CLI_DiaPago2 smallint NULL,
	CLI_CodigoContable varchar(15) COLLATE Modern_Spanish_CI_AS NULL,
	CLI_CadCarnet datetime NULL,
	CLI_Estado smallint NULL,
	CobID char(5) COLLATE Modern_Spanish_CI_AI NULL,
	EJE_IdTesis char(5) COLLATE Modern_Spanish_CI_AI NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_CLIENTES PRIMARY KEY (Id)
);
CREATE NONCLUSTERED INDEX IND_AS_CLIENTES_EmpID
ON TESISSEG.dbo.AS_CLIENTES (EmpID)
INCLUDE (CLI_IdTesis);
CREATE NONCLUSTERED INDEX IND_AS_CLIENTES_CLI_IdTesis_EmpID
ON TESISSEG.dbo.AS_CLIENTES (CLI_IdTesis, EmpID);


-- TESISSEG.dbo.AS_CM_OBJETIVOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CM_OBJETIVOS;

CREATE TABLE TESISSEG.dbo.AS_CM_OBJETIVOS (
	CMO_Id int IDENTITY(1,1) NOT NULL,
	CMO_Nombre varchar(250) COLLATE Modern_Spanish_CI_AS NULL,
	CIA_CodigoDGS varchar(200) COLLATE Modern_Spanish_CI_AS NULL,
	PRO_Id varchar(200) COLLATE Modern_Spanish_CI_AS NULL,
	CMO_TipoPoliza int NULL,
	CMO_TipoMedicion int NULL,
	CMO_Objetivo money NULL,
	CMO_Year int NULL,
	RAM_Id varchar(200) COLLATE Modern_Spanish_CI_AS NULL,
	EJE_Id varchar(200) COLLATE Modern_Spanish_CI_AS NULL,
	CMO_OfiCodes varchar(200) COLLATE Modern_Spanish_CI_AS NULL,
	CMO_VisibleHome int DEFAULT 0 NULL,
	COL_Id varchar(200) COLLATE Modern_Spanish_CI_AS NULL,
	CMO_Orden int DEFAULT 1000 NULL,
	GRM_Id varchar(200) COLLATE Modern_Spanish_CI_AS NULL,
	CMO_Fecha varchar(20) COLLATE Modern_Spanish_CI_AS NULL,
	CMO_Desde datetime NULL,
	CMO_Hasta datetime NULL,
	CMO_Anterior money NULL,
	ColID char(5) COLLATE Modern_Spanish_CI_AI NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_CM_OBJETIVOS PRIMARY KEY (CMO_Id)
);

-- TESISSEG.dbo.AS_CNFRAMOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CNFRAMOS;

CREATE TABLE TESISSEG.dbo.AS_CNFRAMOS (
	CNFRAM_Id int IDENTITY(1,1) NOT NULL,
	RAM_Id int NOT NULL,
	CNFRAM_Tabla varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	CNFRAM_Modelo varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	RAM_IdTesis char(5) COLLATE Modern_Spanish_CI_AI NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK__CNFRAMOS__0425A276 PRIMARY KEY (CNFRAM_Id)
);


-- TESISSEG.dbo.AS_COMPANIAS_ASURNET definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_COMPANIAS_ASURNET;

CREATE TABLE TESISSEG.dbo.AS_COMPANIAS_ASURNET (
	CIA_Id int IDENTITY(1,1) NOT NULL,
    ComID char(5) COLLATE Modern_Spanish_CI_AI NULL,
	CIA_Alias varchar(10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CIA_Nombre varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CIA_Inspector varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CIA_Codigo varchar(20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CIA_Cuenta varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CIA_Cuenta2 varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CIA_Cuenta3 varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CIA_Cuenta4 varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CIA_TipoLiq tinyint NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_COMPANIAS_ASURNET PRIMARY KEY (CIA_Id),
);


-- TESISSEG.dbo.AS_COMPANIAS_PREFERENTES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_COMPANIAS_PREFERENTES;

CREATE TABLE TESISSEG.dbo.AS_COMPANIAS_PREFERENTES (
	CIAP_Id int IDENTITY(1,1) NOT NULL,
	CIA_CodigoDGS varchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	CIAP_Anio int NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_COMPANIAS_PREFERENTES PRIMARY KEY (CIAP_Id)
);

-- TESISSEG.dbo.AS_CONCEPTOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CONCEPTOS;

CREATE TABLE TESISSEG.dbo.AS_CONCEPTOS (
	CPT_Id int IDENTITY(1,1) NOT NULL,
	CPT_Descripcion varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CPT_ObjetoDestino smallint NULL,
	CPT_Fijo tinyint NULL,
	CPT_Opcional tinyint NULL,
	CPT_Orden smallint DEFAULT 0 NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT CONCEPTOS_PK PRIMARY KEY (CPT_Id)
);


-- TESISSEG.dbo.AS_CONDICIONES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CONDICIONES;

CREATE TABLE TESISSEG.dbo.AS_CONDICIONES (
	CND_Id int IDENTITY(1,1) NOT NULL,
	CND_Alias varchar(10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CND_Base smallint NULL,
	CND_ImpMax money NULL,
	CND_ImpMin money NULL,
	CND_ComRecibo money NULL,
	CND_ComAnual money NULL,
	CND_FC datetime NOT NULL,
	USR_Id_FC int NULL,
	CND_FM datetime NOT NULL,
	USR_Id_FM int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_CONDICIONES PRIMARY KEY (CND_Id)
);

-- TESISSEG.dbo.AS_CONDICIONES_GENERICAS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CONDICIONES_GENERICAS;

CREATE TABLE TESISSEG.dbo.AS_CONDICIONES_GENERICAS (
	CNDG_Id int IDENTITY(1,1) NOT NULL,
	CNDG_Propiedad varchar(250) COLLATE Modern_Spanish_CI_AS NOT NULL,
	CNDG_Operador varchar(250) COLLATE Modern_Spanish_CI_AS NOT NULL,
	CNDG_Valor varchar(250) COLLATE Modern_Spanish_CI_AS NOT NULL,
	CNDG_TipoObjeto int NOT NULL,
	CNDG_TipoAdjunto int NOT NULL,
	CNDG_Adjunto int NOT NULL,
	CNDG_Concatenador varchar(3) COLLATE Modern_Spanish_CI_AS DEFAULT 'AND' NOT NULL,
	CNDG_Orden int DEFAULT 0 NOT NULL,
	OldID int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PK_CONDICIONES_GENERICAS PRIMARY KEY (CNDG_Id)
);


-- TESISSEG.dbo.AS_CONEXION_OBJETOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CONEXION_OBJETOS;

CREATE TABLE TESISSEG.dbo.AS_CONEXION_OBJETOS (
	CON_Id int IDENTITY(1,1) NOT NULL,
	CON_TipoObj int NOT NULL,
	CON_ObjId int NULL,
	CON_Fecha datetime NOT NULL,
	Fusion_CON_ObjId char(30) COLLATE Modern_Spanish_CI_AS NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_CONEXION_OBJETOS PRIMARY KEY (CON_Id)
);


-- TESISSEG.dbo.AS_CONFIGURACION_SMTP definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CONFIGURACION_SMTP;

CREATE TABLE TESISSEG.dbo.AS_CONFIGURACION_SMTP (
	Id int IDENTITY(1,1) NOT NULL,
	Servidor varchar(255) COLLATE Modern_Spanish_CI_AS NOT NULL,
	Puerto int NOT NULL,
	Protocolo varchar(3) COLLATE Modern_Spanish_CI_AS DEFAULT 'SSL' NULL,
	Nombre varchar(100) COLLATE Modern_Spanish_CI_AS NULL,
	Usuario varchar(150) COLLATE Modern_Spanish_CI_AS NOT NULL,
	Contrasena varchar(255) COLLATE Modern_Spanish_CI_AS NOT NULL,
	UserId int NULL,
	UserIdTesis int NULL,
	PerfilUsuario int NULL,
	Firma text COLLATE Modern_Spanish_CI_AS NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT CONFIGURACION_SMTP_pk PRIMARY KEY (Id)
);


-- TESISSEG.dbo.AS_CONTRASENAS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CONTRASENAS;

CREATE TABLE TESISSEG.dbo.AS_CONTRASENAS (
	CON_Id int IDENTITY(1,1) NOT NULL,
	USR_Id int NULL,
	USR_Editado nvarchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	CON_Url nvarchar(100) COLLATE Modern_Spanish_CI_AS NOT NULL,
	CON_Sitio nvarchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	CON_Usuario nvarchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	CON_Contrasena nvarchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	CON_Privada tinyint NOT NULL,
	CON_FechaMoficiacion datetime NULL,
	UseID smallint NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_CONTRASENAS PRIMARY KEY (CON_Id)
);


-- TESISSEG.dbo.AS_CONTRATOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CONTRATOS;

CREATE TABLE TESISSEG.dbo.AS_CONTRATOS (
	CNT_Id int IDENTITY(1,1) NOT NULL,
	CNT_Alias varchar(10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	CNT_AutCodigo int NULL,
	CNT_TipoOBJ tinyint NOT NULL,
	CNT_Nombre varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CNT_NumeroContrato varchar(10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CNT_Version int NULL,
	CNT_Fecha datetime NULL,
	CNT_Estado tinyint NULL,
	CNT_Tipo tinyint NULL,
	CNT_SRC tinyint NULL,
	CNT_ControlFirma tinyint NULL,
	CNT_Observaciones text COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CNT_TipoPlantilla tinyint NULL,
	CNT_PathPlantilla varchar(250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CNT_IdPlantilla int NULL,
	USR_Id_FC int NULL,
	USR_Id_FM int NULL,
	CNT_FC datetime NOT NULL,
	CNT_FM datetime NOT NULL,
	CNT_SEPAMetodoPago tinyint NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_CONTRATOS PRIMARY KEY (CNT_Id)
);


-- TESISSEG.dbo.AS_Carpetas definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_Carpetas;

CREATE TABLE TESISSEG.dbo.AS_Carpetas (
	CRP_Id int IDENTITY(1,1) NOT NULL,
	CRP_Nombre varchar(255) COLLATE Modern_Spanish_CI_AS NOT NULL,
	CRP_Tipo_Objeto int NOT NULL,
	CRP_Id_Objeto char(30) COLLATE Modern_Spanish_CI_AS NOT NULL,
	EmpID smallint DEFAULT 0 NULL,
	old_asurnet_id int NULL,
	OldID int NULL,
	CONSTRAINT PK__Carpetas__5357CB674504D3C2 PRIMARY KEY (CRP_Id)
);


-- TESISSEG.dbo.AS_CliDir definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CliDir;

CREATE TABLE TESISSEG.dbo.AS_CliDir (
	CliDir_Id int IDENTITY(1,1) NOT NULL,
	CliDID int NOT NULL,
	CliID int NOT NULL,
	CliCtTel1 varchar(20) COLLATE Modern_Spanish_CI_AS NULL,
	CliCtTel2 varchar(20) COLLATE Modern_Spanish_CI_AS NULL,
	CliCtMov1 varchar(20) COLLATE Modern_Spanish_CI_AS NULL,
	CliCtEma1 varchar(60) COLLATE Modern_Spanish_CI_AS NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_CliDir_ASURNET PRIMARY KEY (CliDir_Id)
);

-- TESISSEG.dbo.AS_DEPARTAMENTOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_DEPARTAMENTOS;

CREATE TABLE TESISSEG.dbo.AS_DEPARTAMENTOS (
	DPT_Id int IDENTITY(1,1) NOT NULL,
	DPT_Nombre varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	DPT_FC datetime NULL,
	USR_ID_FC int NULL,
	DPT_FM datetime NULL,
	USR_ID_FM int NULL,
	USR_ID int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_DEPART PRIMARY KEY (DPT_Id)
);


-- TESISSEG.dbo.AS_DOMAIN_CORREDURIA definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_DOMAIN_CORREDURIA;

CREATE TABLE TESISSEG.dbo.AS_DOMAIN_CORREDURIA (
	DOM_Id int IDENTITY(1,1) NOT NULL,
	DOM_Domain varchar(255) COLLATE Modern_Spanish_CI_AS NOT NULL,
    DOM_DomainDefecto tinyint DEFAULT 0 NULL,
	EmpID int NOT NULL,
	OldID int NULL,
	CONSTRAINT PK__DOMAIN_C__F88A67202C9531FF PRIMARY KEY (DOM_Id)
);
 CREATE NONCLUSTERED INDEX sub_domain_index1 ON TESISSEG.dbo.AS_DOMAIN_CORREDURIA (  DOM_Domain ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;


-- TESISSEG.dbo.AS_DYNAMICITEM definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_DYNAMICITEM;

CREATE TABLE TESISSEG.dbo.AS_DYNAMICITEM (
	DYI_Id int IDENTITY(1,1) NOT NULL,
	DYI_Content varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	DYI_ListType int NULL,
	DYI_Index int NULL,
	AUX_Id int NULL,
	DYI_Fixed tinyint NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_DYNAMICITEM PRIMARY KEY (DYI_Id)
);
 CREATE NONCLUSTERED INDEX IND_DYNAMICITEM ON TESISSEG.dbo.AS_DYNAMICITEM (  DYI_Id ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;


-- TESISSEG.dbo.AS_DiccionarioTareas definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_DiccionarioTareas;

CREATE TABLE TESISSEG.dbo.AS_DiccionarioTareas (
	DTA_Id int IDENTITY(1,1) NOT NULL,
	DTA_Descripcion varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	DTA_PrevisionDuracion real NULL,
	DTA_TipoDuracion varchar(1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	DTA_Prioridad smallint NULL,
	DTA_Tipo smallint DEFAULT 1 NULL,
	DTA_Estado tinyint DEFAULT 3 NOT NULL,
	DTA_Fixed tinyint DEFAULT 0 NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_DiccionarioTareas PRIMARY KEY (DTA_Id)
);


-- TESISSEG.dbo.AS_EJEOFIC definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_EJEOFIC;

CREATE TABLE TESISSEG.dbo.AS_EJEOFIC (
	EJE_ID varchar(5) COLLATE Modern_Spanish_CI_AI NOT NULL,
	OFI_ID int NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT EJEOFIC_PK PRIMARY KEY (EJE_ID,OFI_ID,EmpID)
);


-- TESISSEG.dbo.AS_EMAIL_CONFIRMATIONS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_EMAIL_CONFIRMATIONS;

CREATE TABLE TESISSEG.dbo.AS_EMAIL_CONFIRMATIONS (
	id int IDENTITY(1,1) NOT NULL,
	usersId int NULL,
	usersIdTesis int NOT NULL,
	code char(32) COLLATE Modern_Spanish_CI_AS NOT NULL,
	createdAt int NOT NULL,
	modifiedAt int DEFAULT NULL NULL,
	confirmed char(1) COLLATE Modern_Spanish_CI_AS DEFAULT 'N' NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK__EMAIL_CONFIRMATI__108B795B PRIMARY KEY (id)
);


-- TESISSEG.dbo.AS_EMPRESAS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_EMPRESAS;

CREATE TABLE TESISSEG.dbo.AS_EMPRESAS (
	EMP_Id int IDENTITY(1,1) NOT NULL,
	EMP_Nombre varchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_EMPRESAS PRIMARY KEY (EMP_Id)
);


-- TESISSEG.dbo.AS_EVENT_STORE definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_EVENT_STORE;

CREATE TABLE TESISSEG.dbo.AS_EVENT_STORE (
	id int IDENTITY(1,1) NOT NULL,
	nombre varchar(250) COLLATE Modern_Spanish_CI_AS NOT NULL,
	fecha datetime NOT NULL,
	payload varchar(1000) COLLATE Modern_Spanish_CI_AS NULL,
	procesado tinyint DEFAULT 0 NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_EVENT_STORE PRIMARY KEY (id)
);


-- TESISSEG.dbo.AS_FORMS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_FORMS;

CREATE TABLE TESISSEG.dbo.AS_FORMS (
	FORM_Id int IDENTITY(1,1) NOT NULL,
	FORM_Nombre varchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	FORM_TipoObj int NOT NULL,
	RAM_Id int NULL,
	FORM_Activo tinyint DEFAULT 1 NOT NULL,
	FORM_VisibleCol tinyint DEFAULT 0 NOT NULL,
	FORM_VisibleCli tinyint DEFAULT 0 NOT NULL,
	FORM_Entidad tinyint NULL,
	FORM_TipoIcono int NULL,
	FORM_Icono varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	FORM_Imagen varchar(200) COLLATE Modern_Spanish_CI_AS NULL,
	RAM_IdTesis char(5) COLLATE Modern_Spanish_CI_AI NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_FORMS PRIMARY KEY (FORM_Id)
);

-- TESISSEG.dbo.AS_GLCEJE definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_GLCEJE;

CREATE TABLE TESISSEG.dbo.AS_GLCEJE (
	GCL_Id int NOT NULL,
	EJE_ID varchar(5) COLLATE Modern_Spanish_CI_AI NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT GLCEJE_PK PRIMARY KEY (GCL_Id,EJE_ID,EmpID)
);


-- TESISSEG.dbo.AS_GRUPOSDECOLABORADORES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_GRUPOSDECOLABORADORES;

CREATE TABLE TESISSEG.dbo.AS_GRUPOSDECOLABORADORES (
	GCO_Id int IDENTITY(1,1) NOT NULL,
	GCO_Alias varchar(10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	GCO_Nombre varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	GCO_Observaciones text COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	GCO_FC datetime NULL,
	GCO_FM datetime NULL,
	USR_Id_FC int NULL,
	USR_Id_FM int NULL,
	GCO_OfiCode int DEFAULT 0 NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_GCOL PRIMARY KEY (GCO_Id)
);


-- TESISSEG.dbo.AS_GRUPOSDERAMOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_GRUPOSDERAMOS;

CREATE TABLE TESISSEG.dbo.AS_GRUPOSDERAMOS (
	GRM_Id int IDENTITY(1,1) NOT NULL,
	GRM_Alias varchar(10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	GRM_Nombre varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	GRM_Observaciones text COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	GRM_FC datetime NOT NULL,
	GRM_FM datetime NOT NULL,
	USR_Id_FC int NOT NULL,
	USR_Id_FM int NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_GRUPOSDERAMOS PRIMARY KEY (GRM_Id)
);

-- TESISSEG.dbo.AS_GRUPOS_TIPOS_OPT definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_GRUPOS_TIPOS_OPT;

CREATE TABLE TESISSEG.dbo.AS_GRUPOS_TIPOS_OPT (
	GTO_Id int IDENTITY(1,1) NOT NULL,
	GTO_Nombre varchar(250) COLLATE Modern_Spanish_CI_AS NOT NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_GRUPOS_TIPOS_OPT PRIMARY KEY (GTO_Id)
);


-- TESISSEG.dbo.AS_GestoresDeCuenta definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_GestoresDeCuenta;

CREATE TABLE TESISSEG.dbo.AS_GestoresDeCuenta (
	GCU_Id int IDENTITY(1,1) NOT NULL,
	GCU_Nombre varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT GESTORESDECUENTA_PK PRIMARY KEY (GCU_Id)
);


-- TESISSEG.dbo.AS_ILT_Modalidades definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_ILT_Modalidades;

CREATE TABLE TESISSEG.dbo.AS_ILT_Modalidades (
	ILTM_Id int IDENTITY(1,1) NOT NULL,
	ILTM_Nombre varchar(MAX) COLLATE Modern_Spanish_CI_AS NOT NULL,
	ILTM_Hospitalizacion tinyint DEFAULT 0 NOT NULL,
	ILTM_Accidentes tinyint DEFAULT 0 NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK__ILT_Moda__31DCF38FB06A5E5A PRIMARY KEY (ILTM_Id)
);


-- TESISSEG.dbo.AS_ILT_PrimasHospitalizacion definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_ILT_PrimasHospitalizacion;

CREATE TABLE TESISSEG.dbo.AS_ILT_PrimasHospitalizacion (
	ILTH_Id int IDENTITY(1,1) NOT NULL,
	ILTH_EdadDesde int NOT NULL,
	ILTH_EdadHasta int NOT NULL,
	ILTH_Prima money NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK__ILT_Prim__13BD4D57D7DFC126 PRIMARY KEY (ILTH_Id)
);


-- TESISSEG.dbo.AS_ILT_Profesiones definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_ILT_Profesiones;

CREATE TABLE TESISSEG.dbo.AS_ILT_Profesiones (
	ILTP_Id int IDENTITY(1,1) NOT NULL,
	ILTP_Profesion varchar(MAX) COLLATE Modern_Spanish_CI_AS NULL,
	ILTG_Grupo int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_ILT_Profesiones PRIMARY KEY (ILTP_Id)
);


-- TESISSEG.dbo.AS_ILT_Tarifas definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_ILT_Tarifas;

CREATE TABLE TESISSEG.dbo.AS_ILT_Tarifas (
	ILTT_Id int IDENTITY(1,1) NOT NULL,
	ILTT_GrupoProfesion int NOT NULL,
	ILTT_EdadDesde int NOT NULL,
	ILTT_EdadHasta int NOT NULL,
	ILTT_Franquicia0 money NOT NULL,
	ILTT_Franquicia3 money NOT NULL,
	ILTT_Franquicia7 money NOT NULL,
	ILTT_Franquicia15 money NOT NULL,
	ILTT_Franquicia30 money NOT NULL,
	ILTT_Adicional int NOT NULL,
	ILTT_Accidentes tinyint NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK__ILT_Tari__753FA468B7FD2882 PRIMARY KEY (ILTT_Id)
);



-- TESISSEG.dbo.AS_MAIL_CIAS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_MAIL_CIAS;

CREATE TABLE TESISSEG.dbo.AS_MAIL_CIAS (
	MAIL_Id int IDENTITY(1,1) NOT NULL,
	MAIL_Email nvarchar(100) COLLATE Modern_Spanish_CI_AS NOT NULL,
	CIA_Id int NULL,
	MAIL_TipoObj int NOT NULL,
	MAIL_Contacto nvarchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	MAIL_Tratamiento nvarchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	MAIL_Telf nchar(15) COLLATE Modern_Spanish_CI_AS NULL,
	MAIL_VisibleUsuario tinyint DEFAULT 1 NOT NULL,
	MAIL_VisibleColaborador tinyint DEFAULT 0 NOT NULL,
	MAIL_TelfSecundario nchar(15) COLLATE Modern_Spanish_CI_AS NULL,
	MAIL_Cargo nvarchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	MAIL_Observaciones text COLLATE Modern_Spanish_CI_AS NULL,
	ComID char(5) COLLATE Modern_Spanish_CI_AI NULL,
	idCorreduria int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_MAIL_CIAS PRIMARY KEY (MAIL_Id)
);


-- TESISSEG.dbo.AS_MOTIVOS_ANULACION_OPORTUNIDADES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_MOTIVOS_ANULACION_OPORTUNIDADES;

CREATE TABLE TESISSEG.dbo.AS_MOTIVOS_ANULACION_OPORTUNIDADES (
	MAO_Id int IDENTITY(1,1) NOT NULL,
	MAO_Descripcion varchar(150) COLLATE Modern_Spanish_CI_AS NOT NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT MOTIVOS_ANULACION_OPORTUNIDADES_pk PRIMARY KEY (MAO_Id)
);
 CREATE  UNIQUE NONCLUSTERED INDEX MOTIVOS_ANULACION_OPORTUNIDADES_MAO_Id_uindex ON TESISSEG.dbo.AS_MOTIVOS_ANULACION_OPORTUNIDADES (  MAO_Id ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;



-- TESISSEG.dbo.AS_NOTAS_SINIESTROS_CIA definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_NOTAS_SINIESTROS_CIA;

CREATE TABLE TESISSEG.dbo.AS_NOTAS_SINIESTROS_CIA (
	NSC_Id int IDENTITY(1,1) NOT NULL,
	NSC_Fecha datetime NOT NULL,
	NSC_Hash varchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	NSC_Estado int NOT NULL,
	NSC_Marcado datetime NULL,
	NSC_IdUsuarioMarcado int NULL,
	NSC_Descripcion text COLLATE Modern_Spanish_CI_AS NOT NULL,
	NSC_IdSiniestro int NULL,
	NSC_IdSiniestroTesis char(30) COLLATE Modern_Spanish_CI_AS NULL,
	NSC_AliasSiniestro varchar(15) COLLATE Modern_Spanish_CI_AS NOT NULL,
	NSC_CiaCodigoDgs varchar(10) COLLATE Modern_Spanish_CI_AS NOT NULL,
	NSC_NombreCliente varchar(255) COLLATE Modern_Spanish_CI_AS NOT NULL,
	NSC_IdOficina int NULL,
	EmpDVID int NULL,
	NSC_IdUsuarioTramitador int NULL,
	NSC_IdUsuarioTramitadorTesis int NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_NOTAS_SINIESTROS_CIA PRIMARY KEY (NSC_Id)
);
 CREATE NONCLUSTERED INDEX idx_Hash ON TESISSEG.dbo.AS_NOTAS_SINIESTROS_CIA (  NSC_Hash ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;



-- TESISSEG.dbo.AS_NOTIFICACIONES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_NOTIFICACIONES;

CREATE TABLE TESISSEG.dbo.AS_NOTIFICACIONES (
	NOT_Id int IDENTITY(1,1) NOT NULL,
	NOT_Tipo int NOT NULL,
	NOT_SubTipo int NOT NULL,
	NOT_Fecha datetime NOT NULL,
	NOT_Texto varchar(MAX) COLLATE Modern_Spanish_CI_AS NULL,
	NOT_Visto int DEFAULT 0 NOT NULL,
	NOT_IdObj int NULL,
	COL_VisualId int NULL,
	ColID char(5) COLLATE Modern_Spanish_CI_AI NULL,
	NOT_ObjetoIDTesis varchar(20) COLLATE Modern_Spanish_CI_AS NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_NOTIFICACIONES PRIMARY KEY (NOT_Id)
);
CREATE NONCLUSTERED INDEX IND_AS_NOTIFICACIONES_NOT_ObjetoIDTesis
ON TESISSEG.dbo.AS_NOTIFICACIONES (NOT_Tipo,NOT_SubTipo,EmpID)
INCLUDE (NOT_ObjetoIDTesis);
CREATE NONCLUSTERED INDEX IND_AS_NOTIFICACIONES_NOT_Tipo_NOT_SubTipo_NOT_ObjetoIDTesis_EmpID
ON TESISSEG.dbo.AS_NOTIFICACIONES (NOT_Tipo,NOT_SubTipo,NOT_ObjetoIDTesis,EmpID);


-- TESISSEG.dbo.AS_NOTIFICACIONES_CLIENTES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_NOTIFICACIONES_CLIENTES;

CREATE TABLE TESISSEG.dbo.AS_NOTIFICACIONES_CLIENTES (
	NCLI_Id int IDENTITY(1,1) NOT NULL,
	NCLI_TipoObj int NOT NULL,
	NCLI_ObjId int NOT NULL,
	NCLI_TipoNot int NOT NULL,
	NCLI_Fecha datetime NOT NULL,
	NCLI_Destino int NULL,
	NCLI_ObjetoIDTesis varchar(20) COLLATE Modern_Spanish_CI_AS NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_NOTIFICACIONES_CLIENTES PRIMARY KEY (NCLI_Id)
);
CREATE NONCLUSTERED INDEX IND_AS_NOTIFICACIONES_CLIENTES_NCLI_ObjetoIDTesis
ON TESISSEG.dbo.AS_NOTIFICACIONES_CLIENTES (NCLI_TipoObj,EmpID)
INCLUDE (NCLI_ObjetoIDTesis)


-- TESISSEG.dbo.AS_NOTIFICACIONES_COLABORADORES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_NOTIFICACIONES_COLABORADORES;

CREATE TABLE TESISSEG.dbo.AS_NOTIFICACIONES_COLABORADORES (
	NCOL_Id int IDENTITY(1,1) NOT NULL,
	USR_Id int NULL,
	NCOL_Titulo varchar(250) COLLATE Modern_Spanish_CI_AS NULL,
	NCOL_Texto text COLLATE Modern_Spanish_CI_AS NOT NULL,
	NCOL_FechaNotificacion datetime NOT NULL,
	NCOL_Nombre nvarchar(250) COLLATE Modern_Spanish_CI_AS NULL,
	USRTesis_ID int NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_NOTIFICACIONES_COLABORADORES PRIMARY KEY (NCOL_Id)
);


-- TESISSEG.dbo.AS_OBJETOS_DESTACADOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_OBJETOS_DESTACADOS;

CREATE TABLE TESISSEG.dbo.AS_OBJETOS_DESTACADOS (
	ODS_Id int IDENTITY(1,1) NOT NULL,
	OBJ_Id varchar(20) COLLATE Modern_Spanish_CI_AS NULL,
	ODS_TipoObjeto int NULL,
	ODS_Prioridad int NULL,
	OBJ_IdTesis varchar(100) COLLATE Modern_Spanish_CI_AS NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT OBJETOS_DESTACADOS_pk PRIMARY KEY (ODS_Id)
);
 CREATE  UNIQUE NONCLUSTERED INDEX OBJETOS_DESTACADOS_ODS_Id_uindex ON TESISSEG.dbo.AS_OBJETOS_DESTACADOS (  ODS_Id ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;

-- TESISSEG.dbo.AS_OPCIONESCAMPO definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_OPCIONESCAMPO;

CREATE TABLE TESISSEG.dbo.AS_OPCIONESCAMPO (
	OPC_Id int IDENTITY(1,1) NOT NULL,
	OPC_Valor varchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	OPC_Descripcion varchar(100) COLLATE Modern_Spanish_CI_AS NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_OPCIONESCAMPO PRIMARY KEY (OPC_Id)
);




-- TESISSEG.dbo.AS_PARAMETROS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_PARAMETROS;

CREATE TABLE TESISSEG.dbo.AS_PARAMETROS (
	PAR_Id int IDENTITY(1,1) NOT NULL,
	PAR_Parametro varchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	PAR_Valor varchar(MAX) COLLATE Modern_Spanish_CI_AS NULL,
	PAR_Oficina int NULL,
	PAR_Tipo varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	PAR_Oficina_tesis int NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_PARAMETROS PRIMARY KEY (PAR_Id)
);



-- TESISSEG.dbo.AS_PROFESIONES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_PROFESIONES;

CREATE TABLE TESISSEG.dbo.AS_PROFESIONES (
	PRN_Id int IDENTITY(1,1) NOT NULL,
	PRN_Descripcion varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	PRN_CODIGO varchar(11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_PROFESION PRIMARY KEY (PRN_Id)
);

-- TESISSEG.dbo.AS_RIESGOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_RIESGOS;

CREATE TABLE TESISSEG.dbo.AS_RIESGOS (
	RIE_Id int IDENTITY(1,1) NOT NULL,
	RIE_Tipo smallint NULL,
	RIE_FC datetime NOT NULL,
	RIE_Short varchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	RIE_FM datetime NOT NULL,
	USR_Id_FC int NULL,
	USR_Id_FM int NULL,
	RIE_Descripcion varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_RIESGOS PRIMARY KEY (RIE_Id)
);
 CREATE NONCLUSTERED INDEX IND_FC_USRFC_CLIID ON TESISSEG.dbo.AS_RIESGOS (  RIE_FC ASC  , USR_Id_FC ASC  , RIE_Id DESC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;


-- TESISSEG.dbo.AS_ROLES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_ROLES;

CREATE TABLE TESISSEG.dbo.AS_ROLES (
	ROL_Id int IDENTITY(1,1) NOT NULL,
	ROL_Nombre nvarchar(50) COLLATE Modern_Spanish_CI_AS NULL,
    ROL_GESTOR BIT NOT NULL DEFAULT 0,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_ROLES PRIMARY KEY (ROL_Id)
);


-- TESISSEG.dbo.AS_SMTP_CONFIG definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_SMTP_CONFIG;

CREATE TABLE TESISSEG.dbo.AS_SMTP_CONFIG (
	SMTP_Id int IDENTITY(1,1) NOT NULL,
	SMTP_Servidor nvarchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	SMTP_Puerto nvarchar(5) COLLATE Modern_Spanish_CI_AS NULL,
	SMTP_Protocolo nvarchar(5) COLLATE Modern_Spanish_CI_AS NULL,
	SMTP_Nombre nvarchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	SMTP_Password nvarchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	USR_Id int NULL,
	SMTP_Usuario nvarchar(100) COLLATE Modern_Spanish_CI_AS DEFAULT ' ' NOT NULL,
	SMTP_Firma text COLLATE Modern_Spanish_CI_AS NULL,
	SMTP_AvisosEmail tinyint DEFAULT 1 NOT NULL,
	USR_IdTesis int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_SMTP_CONFIG PRIMARY KEY (SMTP_Id)
);

-- TESISSEG.dbo.AS_TELEFONOS_CIAS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_TELEFONOS_CIAS;

CREATE TABLE TESISSEG.dbo.AS_TELEFONOS_CIAS (
	TEC_Id int IDENTITY(1,1) NOT NULL,
	CIA_CodigoDGS varchar(20) COLLATE Modern_Spanish_CI_AS NOT NULL,
	TEC_Telefono varchar(20) COLLATE Modern_Spanish_CI_AS NOT NULL,
	TEC_Descripcion varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	idCorreduria int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_TELEFONOS_CIAS2 PRIMARY KEY (TEC_Id)
);



-- TESISSEG.dbo.AS_TRAMITADORES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_TRAMITADORES;

CREATE TABLE TESISSEG.dbo.AS_TRAMITADORES (
	TRA_Id int IDENTITY(1,1) NOT NULL,
	USR_Id int NULL,
	TRA_TipoObj int NOT NULL,
	OBJ_Id int NULL,
	Fusion_OBJ_Id int NULL,
	USR_IdTesis int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK__TRAMITAD__8637A4A4A174023F PRIMARY KEY (TRA_Id)
);

-- TESISSEG.dbo.AS_WS_CREDENTIALS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_WS_CREDENTIALS;

CREATE TABLE TESISSEG.dbo.AS_WS_CREDENTIALS (
	id int IDENTITY(1,1) NOT NULL,
	nombre varchar(250) COLLATE Modern_Spanish_CI_AS NOT NULL,
	credentials text COLLATE Modern_Spanish_CI_AS NOT NULL,
	company varchar(10) COLLATE Modern_Spanish_CI_AS NOT NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK__WS_CREDE__3213E83F5B9574DC PRIMARY KEY (id)
);

-- TESISSEG.dbo.AS_FORMCAMP definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_FORMCAMP;

CREATE TABLE TESISSEG.dbo.AS_FORMCAMP (
	Id int IDENTITY(1,1) NOT NULL,
	FORM_Id int NOT NULL,
	CAMP_Id int NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_FORMCAMP PRIMARY KEY (Id),
	CONSTRAINT FK_FORMCAMP_CAMPOS FOREIGN KEY (CAMP_Id) REFERENCES TESISSEG.dbo.AS_CAMPOS(CAMP_Id),
	CONSTRAINT FK_FORMCAMP_FORMS FOREIGN KEY (FORM_Id) REFERENCES TESISSEG.dbo.AS_FORMS(FORM_Id)
);
 CREATE NONCLUSTERED INDEX FORMCAMP_FORM_Id_CAMP_Id_index ON TESISSEG.dbo.AS_FORMCAMP (  FORM_Id ASC  , CAMP_Id ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;

-- TESISSEG.dbo.AS_CARTAS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CARTAS;

CREATE TABLE TESISSEG.dbo.AS_CARTAS (
	CRT_Id int IDENTITY(1,1) NOT NULL,
	CRT_FC datetime NOT NULL,
	CRT_FM datetime NOT NULL,
	USR_Id_FC int NULL,
	USR_Id_FM int NULL,
	CRT_Nombre varchar(250) COLLATE Modern_Spanish_CI_AS NULL,
	CRT_Texto text COLLATE Modern_Spanish_CI_AS NOT NULL,
	CRT_TipoObj int DEFAULT 99 NOT NULL,
	CRT_FormaEnvio varchar(20) COLLATE Modern_Spanish_CI_AS DEFAULT 'email' NOT NULL,
	CRT_Asunto varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	CRT_VisibleCol tinyint DEFAULT 0 NOT NULL,
	CRT_VisibleCli tinyint DEFAULT 0 NOT NULL,
	CRT_IsFolder tinyint NULL,
	CRT_Parent int NULL,
	CRT_Notificar int DEFAULT 0 NULL,
	CRT_Adjuntos text COLLATE Modern_Spanish_CI_AS NULL,
	UseID_FC smallint NULL,
	UseID_FM smallint NULL,
	OldID int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PK_CARTAS PRIMARY KEY (CRT_Id)
);


-- TESISSEG.dbo.AS_CM_OBJETIVOS_CIAS_TESIS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CM_OBJETIVOS_CIAS_TESIS;

CREATE TABLE TESISSEG.dbo.AS_CM_OBJETIVOS_CIAS_TESIS (
	CMO_Id int NOT NULL,
    ComID char(5) COLLATE Modern_Spanish_CI_AI NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PK_CM_OBJETIVOS_CIAS_TESIS PRIMARY KEY (CMO_Id,ComID,EmpID),
	CONSTRAINT FK_CM_OBJETIVOS_CM_OBJETIVOS_CIAS_TESIS FOREIGN KEY (CMO_Id) REFERENCES TESISSEG.dbo.AS_CM_OBJETIVOS(CMO_Id)

);

-- TESISSEG.dbo.AS_CM_OBJETIVOS_EJECUTIVOS_TESIS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CM_OBJETIVOS_EJECUTIVOS_TESIS;

CREATE TABLE TESISSEG.dbo.AS_CM_OBJETIVOS_EJECUTIVOS_TESIS (
	CMO_Id int NOT NULL,
	ColID varchar(5) COLLATE Modern_Spanish_CI_AI NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PK_CM_OBJETIVOS_EJECUTIVOS_TESIS PRIMARY KEY (CMO_Id,ColID,EmpID),
	CONSTRAINT FK_CM_OBJETIVOS_CM_OBJETIVOS_EJECUTIVOS_TESIS FOREIGN KEY (CMO_Id) REFERENCES TESISSEG.dbo.AS_CM_OBJETIVOS(CMO_Id)
);


-- TESISSEG.dbo.AS_CM_OBJETIVOS_GRUPOSRAMOS_TESIS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CM_OBJETIVOS_GRUPOSRAMOS_TESIS;

CREATE TABLE TESISSEG.dbo.AS_CM_OBJETIVOS_GRUPOSRAMOS_TESIS (
	CMO_Id int NOT NULL,
	GRM_Id int NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PK_CM_OBJETIVOS_GRUPOSRAMOS_TESIS PRIMARY KEY (CMO_Id,GRM_Id,EmpID),
	CONSTRAINT FK_CM_OBJETIVOS_CM_OBJETIVOS_GRUPOSDERAMOS_TESIS FOREIGN KEY (CMO_Id) REFERENCES TESISSEG.dbo.AS_CM_OBJETIVOS(CMO_Id),
	CONSTRAINT FK_GRUPOSDERAMOS_CM_OBJETIVOS_GRUPOSDERAMOS_TESIS FOREIGN KEY (GRM_Id) REFERENCES TESISSEG.dbo.AS_GRUPOSDERAMOS(GRM_Id)
);


-- TESISSEG.dbo.AS_CM_OBJETIVOS_OFICINAS_TESIS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CM_OBJETIVOS_OFICINAS_TESIS;

CREATE TABLE TESISSEG.dbo.AS_CM_OBJETIVOS_OFICINAS_TESIS (
	CMO_Id int NOT NULL,
	EmpDVID int NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PK_CM_OBJETIVOS_OFICINAS_TESIS PRIMARY KEY (CMO_Id,EmpDVID,EmpID),
	CONSTRAINT FK_CM_OBJETIVOS_CM_OBJETIVOS_OFICINAS_TESIS FOREIGN KEY (CMO_Id) REFERENCES TESISSEG.dbo.AS_CM_OBJETIVOS(CMO_Id)
);


-- TESISSEG.dbo.AS_CM_OBJETIVOS_PRODUCTOS_TESIS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CM_OBJETIVOS_PRODUCTOS_TESIS;

CREATE TABLE TESISSEG.dbo.AS_CM_OBJETIVOS_PRODUCTOS_TESIS (
	CMO_Id int NOT NULL,
	TipSegId CHAR(10) NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PK_CM_OBJETIVOS_PRODUCTOS_TESIS PRIMARY KEY (CMO_Id,TipSegId,EmpID),
	CONSTRAINT FK_CM_OBJETIVOS_CM_OBJETIVOS_PRODUCTOS_TESIS FOREIGN KEY (CMO_Id) REFERENCES TESISSEG.dbo.AS_CM_OBJETIVOS(CMO_Id)
);


-- TESISSEG.dbo.AS_CM_OBJETIVOS_RAMOS_TESIS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CM_OBJETIVOS_RAMOS_TESIS;

CREATE TABLE TESISSEG.dbo.AS_CM_OBJETIVOS_RAMOS_TESIS (
	CMO_Id int NOT NULL,
	RamId char(5) COLLATE Modern_Spanish_CI_AI NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PK_CM_OBJETIVOS_RAMOS_TESIS PRIMARY KEY (CMO_Id,RamId,EmpID),
	CONSTRAINT FK_CM_OBJETIVOS_CM_OBJETIVOS_RAMOS_TESIS FOREIGN KEY (CMO_Id) REFERENCES TESISSEG.dbo.AS_CM_OBJETIVOS(CMO_Id)
);

-- TESISSEG.dbo.AS_OPORTUNIDADES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_OPORTUNIDADES;

CREATE TABLE TESISSEG.dbo.AS_OPORTUNIDADES (
	OPT_ID int IDENTITY(1,1) NOT NULL,
	CLI_ID int NULL,
	OPT_OPERACION tinyint NULL,
	OPT_ESTADO tinyint NULL,
	OPT_FECHAAPERTURA datetime NULL,
	OPT_FECHACIERRE datetime NULL,
	OPT_FECHAPREVISTA_CIERRE datetime NULL,
	OPT_POREXITO money NULL,
	OPT_FECHALIMITE datetime NULL,
	ETO_ID int NULL,
	TIO_ID int NULL,
	RAM_ID char(5) COLLATE Modern_Spanish_CI_AI NULL,
	COL_ID char(5) COLLATE Modern_Spanish_CI_AI NULL,
	EJE_ID char(5) COLLATE Modern_Spanish_CI_AI NULL,
	POL_ID int NULL,
	OPT_COMPANIA char(30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	OPT_DETALLES_COMPANIA varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	OPT_OBSERVACIONES text COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	OPT_RIESGO_DESC char(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	OPT_Origen char(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	OPT_IMPORTE money NULL,
	USR_FC datetime NULL,
	USR_FM datetime NULL,
	USR_Id_FC int NULL,
	USR_Id_FM int NULL,
	OPT_Precio money NULL,
	OPT_FechaVencimiento datetime NULL,
	MPE_ID int NULL,
	OPT_OfiCode int DEFAULT 0 NULL,
	OPT_Tecnico varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	MON_ID int NULL,
	OPT_OperacionesExentas tinyint DEFAULT 0 NULL,
	OPT_ConfOperacionesExentas varchar(10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	OPT_LPBCOperacion tinyint NULL,
	OPT_DocumentacionIngresos tinyint DEFAULT 0 NULL,
	OPT_OperacionValidada tinyint DEFAULT 0 NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_OPORTUNIDADES PRIMARY KEY (OPT_ID),
	CONSTRAINT FK_DYNAMICITEM_OPORTUNIDADES FOREIGN KEY (ETO_ID) REFERENCES TESISSEG.dbo.AS_DYNAMICITEM(DYI_Id),
	CONSTRAINT FK_DYNAMICITEM_OPORTUNIDADES2 FOREIGN KEY (TIO_ID) REFERENCES TESISSEG.dbo.AS_DYNAMICITEM(DYI_Id)
	);
 CREATE NONCLUSTERED INDEX IDX_OPT_RAM ON TESISSEG.dbo.AS_OPORTUNIDADES (  RAM_ID ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;
 CREATE NONCLUSTERED INDEX IND_CLI_OPT ON TESISSEG.dbo.AS_OPORTUNIDADES (  CLI_ID ASC  , OPT_Origen ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;
 CREATE NONCLUSTERED INDEX IND_OPT_CLIID ON TESISSEG.dbo.AS_OPORTUNIDADES (  CLI_ID ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;


-- TESISSEG.dbo.AS_COMPETIDORES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_COMPETIDORES;

CREATE TABLE TESISSEG.dbo.AS_COMPETIDORES (
	COM_ID int IDENTITY(1,1) NOT NULL,
	OPT_ID int NULL,
	COM_NOMBRE char(30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	COM_COMPANIA char(30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	COM_PRODUCTO char(30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	COM_COMENTARIOS char(60) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	COM_PRECIO money NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_COMPETIDORES PRIMARY KEY (COM_ID),
	CONSTRAINT FK_OPORTUNIDADES_COMPETIDORES FOREIGN KEY (OPT_ID) REFERENCES TESISSEG.dbo.AS_OPORTUNIDADES(OPT_ID)
);
 CREATE NONCLUSTERED INDEX IND_COM_OPT_ID ON TESISSEG.dbo.AS_COMPETIDORES (  OPT_ID ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;


-- TESISSEG.dbo.AS_COMPETIDORES_OPT definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_COMPETIDORES_OPT;

CREATE TABLE TESISSEG.dbo.AS_COMPETIDORES_OPT (
	id int IDENTITY(1,1) NOT NULL,
	oportunidad int NOT NULL,
	compania varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	vencimiento datetime NULL,
	prima money NULL,
	numPoliza varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	ciaId int NULL,
	ciaIdTesis char(5) NULL,
	OldID int NULL,
	EmpID smallint DEFAULT 0 NULL,
	CONSTRAINT PK_COMPETIDORES_OPT PRIMARY KEY (id),
	CONSTRAINT FK_OPORTUNIDADES_COMPETIDORES_OPT FOREIGN KEY (oportunidad) REFERENCES TESISSEG.dbo.AS_OPORTUNIDADES(OPT_ID)
);



-- TESISSEG.dbo.AS_CONDICIONESRAMOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CONDICIONESRAMOS;

CREATE TABLE TESISSEG.dbo.AS_CONDICIONESRAMOS (
	CSR_Id int IDENTITY(1,1) NOT NULL,
	CND_Id int NULL,
	RAM_Id char(5) COLLATE Modern_Spanish_CI_AI NULL,
	CSR_ComPrimer real NULL,
	CSR_ComSegundo real NULL,
	CSR_ComTercero real NULL,
	CSR_ComCuarto real NULL,
	CSR_ComQuinto real NULL,
	CSR_FC datetime NOT NULL,
	USR_Id_FC int NULL,
	CSR_FM datetime NOT NULL,
	USR_Id_FM int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_CONDICIONESRAMOS PRIMARY KEY (CSR_Id),
	CONSTRAINT FK_CONDICIONES_CONDICIONESRAMOS FOREIGN KEY (CND_Id) REFERENCES TESISSEG.dbo.AS_CONDICIONES(CND_Id)
);

-- TESISSEG.dbo.AS_PERSONAS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_PERSONAS;

CREATE TABLE TESISSEG.dbo.AS_PERSONAS (
	PRS_Id int IDENTITY(1,1) NOT NULL,
	PRS_Nombre varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRS_Apellido1 varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRS_Apellido2 varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRS_Direccion varchar(80) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRS_Localidad varchar(80) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRS_CP varchar(5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRS_TelfPal varchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRS_Sexo smallint NULL,
	PRS_Nacimiento datetime NULL,
	PRS_FechaCarnet datetime NULL,
	PRS_CaducidadCarnet datetime NULL,
	PRS_TipoPersona smallint NULL,
	PRS_FC datetime NOT NULL,
	PRS_FM datetime NOT NULL,
	USR_Id_FC_Tesis int NULL,
	USR_Id_FM_Tesis int NULL,
	PRS_Estado smallint DEFAULT 3 NOT NULL,
	PRS_Profesion int NULL,
	PRS_TelfMovil varchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRS_Email varchar(60) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRS_NIF varchar(20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	LOG_FM datetime NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_PERSONAS PRIMARY KEY (PRS_Id),
	CONSTRAINT FK_PROFESIONES_PERSONAS FOREIGN KEY (PRS_Profesion) REFERENCES TESISSEG.dbo.AS_PROFESIONES(PRN_Id)
);



-- TESISSEG.dbo.AS_CONTRARIOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CONTRARIOS;

CREATE TABLE TESISSEG.dbo.AS_CONTRARIOS (
	CTR_Id int IDENTITY(1,1) NOT NULL,
	PRS_Contrario int NULL,
	PRS_Taller int NULL,
	PRS_Conductor int NULL,
	CTR_Modelo varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CTR_Matricula varchar(10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CTR_Danos varchar(80) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CTR_Observaciones text COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CTR_NombreCia varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CTR_TelfCia varchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CTR_Poliza varchar(20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CTR_RefCia varchar(20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CTR_Tramitador varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CTR_Circunstancias varchar(30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	SinNumID int NOT NULL,
	SinSer smallint NOT NULL,
	SinConNum int NOT NULL,
	OldID int NULL,
	EmpID smallint DEFAULT 0 NULL,
	CONSTRAINT PK_CONTRARIOS PRIMARY KEY (CTR_Id),
	CONSTRAINT FK_PERSONAS_CONTRARIOS FOREIGN KEY (PRS_Conductor) REFERENCES TESISSEG.dbo.AS_PERSONAS(PRS_Id)
);

-- TESISSEG.dbo.AS_CONTRASENAS_OFICINAS_TESIS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CONTRASENAS_OFICINAS_TESIS;

CREATE TABLE TESISSEG.dbo.AS_CONTRASENAS_OFICINAS_TESIS (
	Id int IDENTITY(1,1) NOT NULL,
	CON_Id int NULL,
	EmpDVID smallint NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT CONTRASENAS_OFICINAS_TESIS_pk PRIMARY KEY (Id),
	CONSTRAINT FK_CONTRASENAS_CONTRASENAS_OFICINAS_TESIS FOREIGN KEY (CON_Id) REFERENCES TESISSEG.dbo.AS_CONTRASENAS(CON_Id)
);
 CREATE  UNIQUE NONCLUSTERED INDEX CONTRASENAS_OFICINAS_TESIS_Id_uindex ON TESISSEG.dbo.AS_CONTRASENAS_OFICINAS_TESIS (  Id ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;


-- TESISSEG.dbo.AS_GARANTIAS_COMPARATIVO definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_GARANTIAS_COMPARATIVO;

CREATE TABLE TESISSEG.dbo.AS_GARANTIAS_COMPARATIVO (
	id int IDENTITY(1,1) NOT NULL,
	label varchar(250) COLLATE Modern_Spanish_CI_AS NOT NULL,
	valores text COLLATE Modern_Spanish_CI_AS NULL,
	idProyecto int NOT NULL,
	OldID int NULL,
	EmpID smallint DEFAULT 0 NULL,
	CONSTRAINT PK_GARANTIAS_COMPARATIVO PRIMARY KEY (id),
	CONSTRAINT FK_OPORTUNIDADES_GARANTIAS_COMPARATIVO FOREIGN KEY (idProyecto) REFERENCES TESISSEG.dbo.AS_OPORTUNIDADES(OPT_ID)
);


-- TESISSEG.dbo.AS_GRUPOS_TIPOS_JOIN_TABLE definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_GRUPOS_TIPOS_JOIN_TABLE;

CREATE TABLE TESISSEG.dbo.AS_GRUPOS_TIPOS_JOIN_TABLE (
	GTO_Id int NOT NULL,
	DYI_Id int NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PK_GRUPOS_TIPOS_JOIN_TABLE PRIMARY KEY (GTO_Id,DYI_Id,EmpID),
	CONSTRAINT FK_GRUPOS_TIPOS_OPT_GRUPOS_TIPOS_JOIN_TABLE FOREIGN KEY (GTO_Id) REFERENCES TESISSEG.dbo.AS_GRUPOS_TIPOS_OPT(GTO_Id),
	CONSTRAINT FK_DYNAMICITEM_GRUPOS_TIPOS_JOIN_TABLE FOREIGN KEY (DYI_Id) REFERENCES TESISSEG.dbo.AS_DYNAMICITEM(DYI_Id)
);



-- TESISSEG.dbo.AS_INCIDENCIAS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_INCIDENCIAS;

CREATE TABLE TESISSEG.dbo.AS_INCIDENCIAS (
	INC_Id int IDENTITY(1,1) NOT NULL,
	OBJ_Id int NULL,
	INC_Descripcion text COLLATE Modern_Spanish_CI_AS NULL,
	INC_TipoObj smallint NULL,
	INC_FC datetime NOT NULL,
	INC_FM datetime NOT NULL,
    INC_FechaEntrada datetime NOT NULL DEFAULT GETDATE(),
	USR_Id_FC int NULL,
	USR_Id_FM int NULL,
	INC_ReferenciaBorrar varchar(8) COLLATE Modern_Spanish_CI_AS NULL,
	AGN_Id int NULL,
	INC_Referencia varchar(25) COLLATE Modern_Spanish_CI_AS NULL,
	INC_Permanente tinyint DEFAULT 0 NULL,
	CDI_Id int NULL,
	INC_CliPublicable tinyint NULL,
	INC_GenPublicable tinyint NULL,
	RFR_Id int NULL,
	INC_Cierre datetime NULL,
	INC_Situacion smallint DEFAULT 2 NULL,
	INC_Manual bit DEFAULT 0 NULL,
	CLI_Id int NULL,
	INC_TipoIncAviso tinyint NULL,
	INC_UsuarioCierre int NULL,
	INC_TextoCierre varchar(250) COLLATE Modern_Spanish_CI_AS NULL,
	INC_IdAvisoPadre int NULL,
	SUP_Id int NULL,
	INC_FechaPrevista datetime NULL,
	INA_Id int NULL,
	Fusion_CLI_Id int NULL,
	Fusion_OBJ_Id varchar(30) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_USR_Id_FC int NULL,
	Fusion_USR_Id_FM int NULL,
	Fusion_INC_UsuarioCierre int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	GesNum int NULL,
	OldID int NULL,
    INC_PublicableColaborador TINYINT NOT NULL DEFAULT 1,
    INC_PublicableColaboradorBackup TINYINT NOT NULL DEFAULT 1,
    Aviso_Gestor_Comercial smallint not null DEFAULT 0,
    Aviso_Gestor_Administrativo smallint not null DEFAULT 0,
    Aviso_Tramitador_Sinietros smallint not null DEFAULT 0,
    Aviso_Todos smallint not null DEFAULT 0,
    Aviso_Colaborador smallint not null DEFAULT 0,
    Aviso_Colaboradores_Todos smallint not null DEFAULT 0,
	CONSTRAINT PK_INCIDENCIAS PRIMARY KEY (INC_Id)
);
CREATE NONCLUSTERED INDEX IND_AS_INCIDENCIAS_EmpID ON TESISSEG.dbo.AS_INCIDENCIAS (  EmpID ASC )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;
CREATE NONCLUSTERED INDEX IND_AS_INCIDENCIAS_AGN_ObjetoEmp ON TESISSEG.dbo.AS_INCIDENCIAS (  INC_TipoObj ASC  , Fusion_OBJ_Id ASC , EmpID ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;
CREATE NONCLUSTERED INDEX IND_AS_INCIDENCIAS_Fusion_OBJ_Id_GesNum
ON TESISSEG.dbo.AS_INCIDENCIAS (INC_TipoObj,EmpID)
INCLUDE (Fusion_OBJ_Id,GesNum);
CREATE NONCLUSTERED INDEX  IND_AS_INCIDENCIAS_Fusion_CLI_Id
ON TESISSEG.dbo.AS_INCIDENCIAS (INC_TipoObj,INC_Situacion,Fusion_USR_Id_FC,EmpID)
INCLUDE (Fusion_CLI_Id);
CREATE NONCLUSTERED INDEX IND_AS_INCIDENCIAS_INC_TipoOb_EmpID
ON TESISSEG.dbo.AS_INCIDENCIAS (INC_TipoObj,EmpID)
INCLUDE (Fusion_CLI_Id,Fusion_OBJ_Id);
CREATE NONCLUSTERED INDEX IND_AS_INCIDENCIAS_INC_TipoObj_EmpID_INC_FC
ON TESISSEG.dbo.AS_INCIDENCIAS (INC_TipoObj,EmpID)
INCLUDE (INC_FC,Fusion_CLI_Id,Fusion_OBJ_Id);
CREATE NONCLUSTERED INDEX AS_INCIDENCIAS_Fusion_OBJ_Id_IDX ON dbo.AS_INCIDENCIAS (  Fusion_OBJ_Id ASC  )  
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ];
CREATE NONCLUSTERED INDEX AS_INCIDENCIAS_INC_FC_IDX ON dbo.AS_INCIDENCIAS (  INC_FC ASC  )  
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ];
CREATE NONCLUSTERED INDEX AS_INCIDENCIAS_INC_FC_IDX2 ON dbo.AS_INCIDENCIAS (  INC_FC DESC  )  
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ];
CREATE NONCLUSTERED INDEX AS_INCIDENCIAS_INC_TipoObj_IDX ON dbo.AS_INCIDENCIAS (  INC_TipoObj ASC  )  
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ];
CREATE NONCLUSTERED INDEX AS_INCIDENCIAS_INC_TipoObj_IDX2 ON dbo.AS_INCIDENCIAS (  INC_TipoObj ASC  , EmpID ASC  , Fusion_OBJ_Id ASC  )  
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ];
CREATE NONCLUSTERED INDEX AS_INCIDENCIAS_INC_TipoObj_IDX3 ON dbo.AS_INCIDENCIAS (  INC_TipoObj ASC  , EmpID ASC  , INC_FC ASC  )  
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ];



-- TESISSEG.dbo.AS_INCIDENCIASCLIENTES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_INCIDENCIASCLIENTES;

CREATE TABLE TESISSEG.dbo.AS_INCIDENCIASCLIENTES (
	INC_Id int IDENTITY(1,1) NOT NULL,
	OBJ_Id char(10) COLLATE Modern_Spanish_CI_AS NULL,
	INC_Descripcion text COLLATE Modern_Spanish_CI_AS NULL,
	INC_TipoObj smallint NULL,
	INC_FC datetime NOT NULL,
	INC_FM datetime NOT NULL,
    INC_FechaEntrada datetime NOT NULL DEFAULT GETDATE(),
    INC_FechaAlarma datetime NOT NULL DEFAULT GETDATE(),
	USR_Id_FC int NULL,
	USR_Id_FM int NULL,
	INC_ReferenciaBorrar varchar(8) COLLATE Modern_Spanish_CI_AS NULL,
	AGN_Id int NULL,
	INC_Referencia varchar(25) COLLATE Modern_Spanish_CI_AS NULL,
	INC_Permanente tinyint DEFAULT 0 NULL,
	CDI_Id int NULL,
	INC_CliPublicable tinyint NULL,
	INC_GenPublicable tinyint NULL,
	RFR_Id int NULL,
	INC_Cierre datetime NULL,
	INC_Situacion smallint DEFAULT 2 NULL,
	INC_Manual bit DEFAULT 0 NULL,
	CLI_Id int NULL,
	INC_TipoIncAviso tinyint NULL,
	INC_UsuarioCierre int NULL,
	INC_TextoCierre varchar(250) COLLATE Modern_Spanish_CI_AS NULL,
	INC_IdAvisoPadre int NULL,
	SUP_Id int NULL,
	INC_FechaPrevista datetime NULL,
	INA_Id int NULL,
	INC_PerfilCreador int NULL,
	INC_IdCreador int NULL,
	INC_NombreCreador varchar(250) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_OBJ_Id char(30) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_USR_Id_FC int NULL,
	Fusion_USR_Id_FM int NULL,
	Fusion_INC_UsuarioCierre int NULL,
	Fusion_CLI_Id int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_INCIDENCIASCLIENTES PRIMARY KEY (INC_Id)
);

-- TESISSEG.dbo.AS_COLABORADORES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_COLABORADORES;

CREATE TABLE TESISSEG.dbo.AS_COLABORADORES (
	COL_MyId int IDENTITY(1,1) NOT NULL,
	COL_VisualId char(4) COLLATE Modern_Spanish_CI_AS NULL,
	COL_Contacto varchar(MAX) COLLATE Modern_Spanish_CI_AS NULL,
	COL_Titular varchar(MAX) COLLATE Modern_Spanish_CI_AS NULL,
	COL_Colegiado varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	COL_Referencias varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	COL_Contrato int DEFAULT 0 NOT NULL,
	COL_RecordatorioNotif int DEFAULT 0 NOT NULL,
	COL_Newsletter int DEFAULT 0 NOT NULL,
	COL_Comunidades varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	COL_CuentaContable varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	COL_Notas text COLLATE Modern_Spanish_CI_AS NULL,
	COL_Campania int NULL,
	USR_Propietario int NULL,
	CALCOL_Id int NULL,
	COL_Descripcion text COLLATE Modern_Spanish_CI_AS NULL,
	COL_Marketing int DEFAULT 0 NULL,
	COL_VerLiquidaciones int DEFAULT 1 NULL,
	COL_Edicion int NULL,
	COL_Fecha_Alta datetime NULL,
	COL_UltimoAcceso datetime NULL,
	CAL_Id int NULL,
	PROG_Id int NULL,
	COL_AltaCliente int NULL,
	COL_UltimoAccesoApp datetime NULL,
	COL_Oficina int NULL,
	EJE_Id char(4) COLLATE Modern_Spanish_CI_AS NULL,
	COL_CrmId int NULL,
	COL_GestionIncCli int NULL,
	COL_DealId int NULL,
	COL_RecibirCli tinyint DEFAULT 1 NOT NULL,
	COL_EmailCli int NULL,
	COL_ResumenCli tinyint DEFAULT 0 NOT NULL,
	COL_RecibirCol tinyint DEFAULT 1 NOT NULL,
	COL_EmailCol int NULL,
	COL_ResumenCol tinyint DEFAULT 0 NOT NULL,
	COL_RecibirPol tinyint DEFAULT 1 NOT NULL,
	COL_EmailPol int NULL,
	COL_ResumenPol tinyint DEFAULT 0 NOT NULL,
	COL_RecibirRec tinyint DEFAULT 1 NOT NULL,
	COL_EmailRec int NULL,
	COL_ResumenRec tinyint DEFAULT 0 NOT NULL,
	COL_RecibirSin tinyint DEFAULT 1 NOT NULL,
	COL_EmailSin int NULL,
	COL_ResumenSin tinyint DEFAULT 0 NOT NULL,
	COL_RecibirOpt tinyint DEFAULT 1 NOT NULL,
	COL_EmailOpt int NULL,
	COL_ResumenOpt tinyint DEFAULT 0 NOT NULL,
	COL_RecibirGen tinyint DEFAULT 1 NOT NULL,
	COL_EmailGen int NULL,
	COL_ResumenGen tinyint DEFAULT 0 NOT NULL,
	COL_RecibirCM tinyint DEFAULT 1 NOT NULL,
	COL_EmailCM int NULL,
	COL_ResumenCM tinyint DEFAULT 0 NOT NULL,
	GES_Id int NULL,
	COL_RecibosDescargar varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	COL_VerArchivosPerfil tinyint DEFAULT 0 NOT NULL,
	COL_CarteraPrimaNeta money DEFAULT 0 NULL,
	COL_PolizasVigor int DEFAULT 0 NULL,
	COL_TipoPersona varchar(1) COLLATE Modern_Spanish_CI_AS DEFAULT 'F' NULL,
	COL_Irpf real NULL,
	COL_NumColegiado varchar(20) COLLATE Modern_Spanish_CI_AS NULL,
	COL_Zona varchar(3) COLLATE Modern_Spanish_CI_AS NULL,
	COL_NoLiquidar tinyint NULL,
	COL_LimiteLiq money NULL,
	COL_FacturarSiCero tinyint NULL,
	COL_Facturar tinyint NULL,
	COL_TipoAux tinyint DEFAULT 1 NULL,
	CND_Id int NULL,
	GCO_ID int NULL,
	USR_PropietarioTesis int NULL,
	EJE_IdTesis char(5) COLLATE Modern_Spanish_CI_AI NULL,
	GES_IdTesis char(5) COLLATE Modern_Spanish_CI_AI NULL,
	COL_TesisId char(5) COLLATE Modern_Spanish_CI_AI NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	COL_Alias varchar(10) COLLATE Modern_Spanish_CI_AI NULL,
	OldID int NULL,
	CONSTRAINT PK_COLABORADORES PRIMARY KEY (COL_MyId),
	CONSTRAINT FK_COLABORADORES_CALIFICACIONES_COLABORADORES FOREIGN KEY (CALCOL_Id) REFERENCES TESISSEG.dbo.AS_CALIFICACIONES_COLABORADORES(CALCOL_Id),
	CONSTRAINT FK_COLABORADORES_CONDICIONES FOREIGN KEY (CND_Id) REFERENCES TESISSEG.dbo.AS_CONDICIONES(CND_Id),
	CONSTRAINT FK_COLABORADORES_GRUPOSDECOLABORADORES FOREIGN KEY (GCO_ID) REFERENCES TESISSEG.dbo.AS_GRUPOSDECOLABORADORES(GCO_ID)

);

-- TESISSEG.dbo.AS_USUARIOS_COLABORADORES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_USUARIOS_COLABORADORES;

CREATE TABLE TESISSEG.dbo.AS_USUARIOS_COLABORADORES (
	USER_id int IDENTITY(1,1) NOT NULL,
	USER_username varchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	USER_pass varchar(MAX) COLLATE Modern_Spanish_CI_AS NULL,
	USER_fecha_alta varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	USER_nombre varchar(MAX) COLLATE Modern_Spanish_CI_AS NULL,
	USER_cif varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	USER_mail varchar(MAX) COLLATE Modern_Spanish_CI_AS NULL,
	USER_perfil int NOT NULL,
	USER_colid int NULL,
	USER_activo int NULL,
	USER_confirm_hash varchar(MAX) COLLATE Modern_Spanish_CI_AS NULL,
	USER_webid int NULL,
	USER_appToken varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	USER_usuariotesis int NULL,
    CONSTRAINT PK_USUARIOS_COLABORADORES PRIMARY KEY (USER_id),
	CONSTRAINT FK_COLABORADORES_USUARIOS_COLABORADORES FOREIGN KEY (USER_colid) REFERENCES TESISSEG.dbo.AS_COLABORADORES(COL_MyId)
);


-- TESISSEG.dbo.AS_ITEM_USUARIOCOLABORADOR definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_ITEM_USUARIOCOLABORADOR;

CREATE TABLE TESISSEG.dbo.AS_ITEM_USUARIOCOLABORADOR (
	IUC_Id int IDENTITY(1,1) NOT NULL,
	IUC_TipoObjeto int NOT NULL,
	IUC_IdObjeto int NULL,
	Fusion_IUC_IdObjeto int NULL,
	USR_Id int NOT NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK__ITEM_USU__A5A3B62D5668B5EE PRIMARY KEY (IUC_Id),
	CONSTRAINT FK_USUARIOS_COLABORADORES_ITEM_USUARIOCOLABORADOR FOREIGN KEY (USR_Id) REFERENCES TESISSEG.dbo.AS_USUARIOS_COLABORADORES(USER_id)
);


-- TESISSEG.dbo.AS_OPORTUNIDADES_RIESGOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_OPORTUNIDADES_RIESGOS;

CREATE TABLE TESISSEG.dbo.AS_OPORTUNIDADES_RIESGOS (
	OPT_ID int NOT NULL,
	RIE_ID int NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT OPORTUNIDADES_RIESGOS_PK PRIMARY KEY (OPT_ID,RIE_ID,EmpID),
	CONSTRAINT FK_OPORTUNIDADES_OPORTUNIDADES_RIESGOS FOREIGN KEY (OPT_ID) REFERENCES TESISSEG.dbo.AS_OPORTUNIDADES(OPT_ID),
	CONSTRAINT FK_RIESGOS_OPORTUNIDADES_RIESGOS FOREIGN KEY (RIE_ID) REFERENCES TESISSEG.dbo.AS_RIESGOS(RIE_ID)
);


-- TESISSEG.dbo.AS_PERITOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_PERITOS;

CREATE TABLE TESISSEG.dbo.AS_PERITOS (
	SinNumID int NOT NULL,
	SinSer int NOT NULL,
	PRS_Id int NOT NULL,
	PRT_Peritaje datetime NULL,
	PRT_Importe money NULL,
	PRT_Importe2 real NULL,
	PRT_Importe3 real NULL,
	PRT_Peritaje2 datetime NULL,
	PRT_Peritaje3 datetime NULL,
	PRT_Lugar varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRT_Observaciones varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRT_ID int IDENTITY(1,1) NOT NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_PERITOS PRIMARY KEY (SinNumID,SinSer,PRS_Id),
	CONSTRAINT FK_PERSONAS_PERITOS FOREIGN KEY (PRS_Id) REFERENCES TESISSEG.dbo.AS_PERSONAS(PRS_Id)
);


-- TESISSEG.dbo.AS_SINIESTROS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_SINIESTROS;

CREATE TABLE TESISSEG.dbo.AS_SINIESTROS (
	SIN_MyId int IDENTITY(1,1) NOT NULL,
	SIN_Id int NOT NULL,
	REF_Asistencia varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	SIN_ContactoNombre varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	SIN_ContactoApellidos varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	SIN_ContactoTelefono varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	SIN_ContactoTipo varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	SIN_ContactoEmail varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	EMP_Id int NULL,
	USR_Tramitador int NULL,
	SIN_UrlWeb varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	WS_Credentials int DEFAULT NULL NULL,
	SIN_Proteccion varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	SIN_Cuerpo varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	SIN_Descripcion varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	SIN_IdSiniestro int NULL,
	SIN_IdFechaSiniestro int NULL,
	SIN_DanosMateriales smallint NULL,
	SIN_Atestados smallint NULL,
	SIN_Victima smallint NULL,
	SIN_Consorcio smallint NULL,
	SIN_ReclamacionJA smallint NULL,
	SIN_PSRTaller int NULL,
	SIN_ConductorFechaCaducidadCarnet datetime NULL,
	SIN_ConductorSexo varchar(5) COLLATE Modern_Spanish_CI_AI NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	USR_TramitadorTesis int NULL,
	CONSTRAINT PK_AS_SINIESTROS PRIMARY KEY (SIN_MyId),
	CONSTRAINT FK_EMPRESAS_SINIESTROS FOREIGN KEY (EMP_Id) REFERENCES TESISSEG.dbo.AS_EMPRESAS(EMP_Id),
	CONSTRAINT FK_PERSONAS_SINIESTROS FOREIGN KEY (SIN_PSRTaller) REFERENCES TESISSEG.dbo.AS_PERSONAS(PRS_Id)
);
CREATE NONCLUSTERED INDEX IND_AS_SINIESTROS_EmpID
ON TESISSEG.dbo.AS_SINIESTROS (EmpID)
INCLUDE (SIN_IdSiniestro,SIN_IdFechaSiniestro);
CREATE NONCLUSTERED INDEX IND_Clientes_EmpID_EmpDVID
ON TESISSEG.dbo.Clientes (EmpID,EmpDVID)


-- TESISSEG.dbo.AS_SMS_ENVIADOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_SMS_ENVIADOS;

CREATE TABLE TESISSEG.dbo.AS_SMS_ENVIADOS (
	SMS_Id int IDENTITY(1,1) NOT NULL,
	SMS_NumeroTelefono varchar(20) COLLATE Modern_Spanish_CI_AS NOT NULL,
	SMS_Texto varchar(320) COLLATE Modern_Spanish_CI_AS NOT NULL,
	SMS_ObjId int NULL,
	Fusion_SMS_ObjId char(30) COLLATE Modern_Spanish_CI_AS NULL,
	SMS_TipoObjeto int NOT NULL,
	SMS_Fecha datetime NOT NULL,
	SMS_Usuario int NULL,
	SMS_UsuarioColaborador int NULL,
	UseID smallint NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK__SMS_ENVI__CFF1641954AC919E PRIMARY KEY (SMS_Id),
	CONSTRAINT FK_USUARIOS_COLABORADORES_SMS_ENVIADOS FOREIGN KEY (SMS_UsuarioColaborador) REFERENCES TESISSEG.dbo.AS_USUARIOS_COLABORADORES(USER_id)
);


-- TESISSEG.dbo.AS_PUSH_DEVICES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_PUSH_DEVICES;

CREATE TABLE TESISSEG.dbo.AS_PUSH_DEVICES (
	DVC_Id int IDENTITY(1,1) NOT NULL,
	DVC_Token varchar(MAX) COLLATE Modern_Spanish_CI_AS NULL,
	COL_Id int NULL,
	DVC_System varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	DVC_Send int DEFAULT 1 NULL,
	DVC_Username varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	USER_Id int NULL,
	ColID char(5) COLLATE Modern_Spanish_CI_AI NULL,
	OldID int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PK_PUSH_DEVICES PRIMARY KEY (DVC_Id),
	CONSTRAINT FK_USUARIOS_COLABORADORES_PUSH_DEVICES FOREIGN KEY (USER_Id) REFERENCES TESISSEG.dbo.AS_USUARIOS_COLABORADORES(USER_id)
);


-- TESISSEG.dbo.AS_TAREASINC definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_TAREASINC;

CREATE TABLE TESISSEG.dbo.AS_TAREASINC (
	TAR_ID int IDENTITY(1,1) NOT NULL,
	OBJ_Id int NULL,
	TAR_TipoObj smallint NULL,
	DTA_Id int NULL,
	TAR_Fecha datetime NULL,
	TAR_Hora varchar(5) COLLATE Modern_Spanish_CI_AS NULL,
	TAR_Observaciones text COLLATE Modern_Spanish_CI_AS NULL,
	TAR_Situacion smallint NULL,
	TAR_UsuarioDestino int NULL,
	TAR_Prioridad smallint NULL,
	USR_Id_FC int NULL,
	USR_Id_FM int NULL,
	TAR_FC datetime NOT NULL,
	TAR_FM datetime NOT NULL,
	TAR_PrevisionResolucion datetime NULL,
	TAR_Resolucion datetime NULL,
	TAR_PrevisionDuracion real NULL,
	TAR_Duracion real NULL,
	TAR_TipoDuracion varchar(1) COLLATE Modern_Spanish_CI_AS NULL,
	TAR_ObserResolucion text COLLATE Modern_Spanish_CI_AS NULL,
	TAR_Tipo smallint DEFAULT 1 NULL,
	TAR_UsrId_Resolucion int NULL,
	TAR_PeticionId int NULL,
	SIN_Id int NULL,
	INC_Id int NULL,
	OPT_Id int NULL,
	CLI_Id int NULL,
	CIA_Id int NULL,
	POL_Id int NULL,
	REC_Id int NULL,
	TAR_Dependencia_Id int NULL,
	TAR_DiasDif int NULL,
	INA_Id int NULL,
	TAR_FechaAnulacion datetime NULL,
	TAR_TipoDiferencia varchar(1) COLLATE Modern_Spanish_CI_AS NULL,
	TAR_Diferencia real NULL,
	TAR_DestinoMismoUsuario tinyint NULL,
	TAR_TipoIncidencia tinyint NULL,
	GCN_ID int NULL,
	TAR_EntryId varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_OBJ_Id char(30) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_USR_Id_FM int NULL,
	Fusion_USR_Id_FC int NULL,
	Fusion_TAR_UsuarioDestino int NULL,
	Fusion_TAR_UsrId_Resolucion int NULL,
	Fusion_SIN_Id char(30) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_OPT_Id int NULL,
	Fusion_CLI_Id char(30) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_CIA_Id char(5) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_POL_Id char(30) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_REC_Id char(30) COLLATE Modern_Spanish_CI_AS NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_TAREASINC PRIMARY KEY (TAR_ID),
	CONSTRAINT FK_DiccionarioTareas_TAREASINC FOREIGN KEY (DTA_Id) REFERENCES TESISSEG.dbo.AS_DiccionarioTareas(DTA_Id),
	CONSTRAINT FK_INCIDENCIAS_TAREASINC FOREIGN KEY (INC_Id) REFERENCES TESISSEG.dbo.AS_INCIDENCIAS(INC_Id),
	CONSTRAINT FK_OPORTUNIDADES_TAREASINC FOREIGN KEY (Fusion_OPT_Id) REFERENCES TESISSEG.dbo.AS_OPORTUNIDADES(OPT_ID)
);
CREATE NONCLUSTERED INDEX IND_AS_TAREASINC_EmpID ON TESISSEG.dbo.AS_TAREASINC (  EmpID ASC )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;
CREATE NONCLUSTERED INDEX IND_AS_TAREASINC_ObjetoEmp ON TESISSEG.dbo.AS_TAREASINC (  TAR_TipoObj ASC  , OBJ_Id ASC , EmpID ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;
CREATE NONCLUSTERED INDEX AS_TAREASINC_OBJ_Id_IDX2 ON dbo.AS_TAREASINC (  OBJ_Id ASC  , TAR_TipoObj ASC  , TAR_Situacion ASC  , EmpID ASC  )  
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ];


-- TESISSEG.dbo.AS_TAREASINCCLIENTES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_TAREASINCCLIENTES;

CREATE TABLE TESISSEG.dbo.AS_TAREASINCCLIENTES (
	TAR_ID int IDENTITY(1,1) NOT NULL,
	OBJ_Id int NULL,
	TAR_TipoObj smallint NULL,
	DTA_Id int NULL,
	TAR_Fecha datetime NULL,
	TAR_Hora varchar(5) COLLATE Modern_Spanish_CI_AS NULL,
	TAR_Observaciones text COLLATE Modern_Spanish_CI_AS NULL,
	TAR_Situacion smallint NULL,
	TAR_UsuarioDestino int NULL,
	TAR_Prioridad smallint NULL,
	USR_Id_FC int NULL,
	USR_Id_FM int NULL,
	TAR_FC datetime NOT NULL,
	TAR_FM datetime NOT NULL,
	TAR_PrevisionResolucion datetime NULL,
	TAR_Resolucion datetime NULL,
	TAR_PrevisionDuracion real NULL,
	TAR_Duracion real NULL,
	TAR_TipoDuracion varchar(1) COLLATE Modern_Spanish_CI_AS NULL,
	TAR_ObserResolucion text COLLATE Modern_Spanish_CI_AS NULL,
	TAR_Tipo smallint DEFAULT 1 NULL,
	TAR_UsrId_Resolucion int NULL,
	TAR_PeticionId int NULL,
	SIN_Id int NULL,
	INC_Id int NULL,
	OPT_Id int NULL,
	CLI_Id int NULL,
	CIA_Id int NULL,
	POL_Id int NULL,
	REC_Id int NULL,
	TAR_Dependencia_Id int NULL,
	TAR_DiasDif int NULL,
	INA_Id int NULL,
	TAR_FechaAnulacion datetime NULL,
	TAR_TipoDiferencia varchar(1) COLLATE Modern_Spanish_CI_AS NULL,
	TAR_Diferencia real NULL,
	TAR_DestinoMismoUsuario tinyint NULL,
	TAR_TipoIncidencia tinyint NULL,
	GCN_ID int NULL,
	TAR_EntryId varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_USR_Id_FC int NULL,
	Fusion_USR_Id_FM int NULL,
	Fusion_TAR_UsuarioDestino int NULL,
	Fusion_TAR_UsrId_Resolucion int NULL,
	Fusion_SIN_Id char(30) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_OPT_Id int NULL,
	Fusion_CLI_Id char(30) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_CIA_Id char(30) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_POL_Id char(30) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_REC_Id char(30) COLLATE Modern_Spanish_CI_AS NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_TAREASINCCLIENTES PRIMARY KEY (TAR_ID),
	CONSTRAINT FK_DiccionarioTareas_TAREASINCCLIENTES FOREIGN KEY (DTA_Id) REFERENCES TESISSEG.dbo.AS_DiccionarioTareas(DTA_Id),
	CONSTRAINT FK_INCIDENCIASCLIENTES_TAREASINCCLIENTES FOREIGN KEY (INC_Id) REFERENCES TESISSEG.dbo.AS_INCIDENCIASCLIENTES(INC_Id)
);



-- TESISSEG.dbo.AS_TELEFONOS_RAMOS_TESIS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_TELEFONOS_RAMOS_TESIS;

CREATE TABLE TESISSEG.dbo.AS_TELEFONOS_RAMOS_TESIS (
	TEC_Id int NOT NULL,
	RAM_Id char(5) COLLATE Modern_Spanish_CI_AI NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PK_TELEFONOS_RAMOS_TESIS PRIMARY KEY (TEC_Id,RAM_Id,EmpID),
	CONSTRAINT FK_TELEFONOS_CIAS_TELEFONOS_RAMOS_TESIS FOREIGN KEY (TEC_Id) REFERENCES TESISSEG.dbo.AS_TELEFONOS_CIAS(TEC_Id)
);


-- TESISSEG.dbo.AS_WSC_OFICINAS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_WSC_OFICINAS;

CREATE TABLE TESISSEG.dbo.AS_WSC_OFICINAS (
	id int IDENTITY(1,1) NOT NULL,
	WSC_Id int NOT NULL,
	OFI_Id int NULL,
	EmpDVID int NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT WSC_OFICINAS_pk PRIMARY KEY (id),
	CONSTRAINT WSC_OFICINAS_WS_CREDENTIALS_id_fk FOREIGN KEY (WSC_Id) REFERENCES TESISSEG.dbo.AS_WS_CREDENTIALS(id)
);

-- TESISSEG.dbo.AS_VALORES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_VALORES;

CREATE TABLE TESISSEG.dbo.AS_VALORES (
	VAL_Id int IDENTITY(1,1) NOT NULL,
	VAL_Descripcion varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	CPT_Id int NULL,
	VAL_Orden int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT VALORES_PK PRIMARY KEY (VAL_Id),
	CONSTRAINT FK_VAL_CONCEPTOS FOREIGN KEY (CPT_Id) REFERENCES TESISSEG.dbo.AS_CONCEPTOS(CPT_Id)
);
 CREATE NONCLUSTERED INDEX IND_VAL_CONCEPTOS ON TESISSEG.dbo.AS_VALORES (  CPT_Id ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;



-- TESISSEG.dbo.AS_clicrit definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_clicrit;

CREATE TABLE TESISSEG.dbo.AS_clicrit (
	CLI_Id int NOT NULL,
	CPT_Id int NOT NULL,
	VAL_Id int NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PK_clicrit PRIMARY KEY (CLI_Id,CPT_Id,VAL_Id),
	CONSTRAINT FK_CLICRIT_CONCEPTOS FOREIGN KEY (CPT_Id) REFERENCES TESISSEG.dbo.AS_CONCEPTOS(CPT_Id),
	CONSTRAINT FK_CLICRIT_VALORES FOREIGN KEY (VAL_Id) REFERENCES TESISSEG.dbo.AS_VALORES(VAL_Id)
);
 CREATE NONCLUSTERED INDEX IND_clicrit_CONCEPTOS ON TESISSEG.dbo.AS_clicrit (  CPT_Id ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;
 CREATE NONCLUSTERED INDEX IND_clicrit_VALORES ON TESISSEG.dbo.AS_clicrit (  VAL_Id ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;
 CREATE NONCLUSTERED INDEX ind_clicrit_clientes ON TESISSEG.dbo.AS_clicrit (  CLI_Id ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;


-- TESISSEG.dbo.AS_usrdpt definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_usrdpt;

CREATE TABLE TESISSEG.dbo.AS_usrdpt (
	USR_Id int NOT NULL,
	DPT_Id int NOT NULL,
	USD_Contador int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT usrdpt_PK PRIMARY KEY (USR_Id,DPT_Id,EmpID),
	CONSTRAINT FK_DEPARTAMENTOS FOREIGN KEY (DPT_Id) REFERENCES TESISSEG.dbo.AS_DEPARTAMENTOS(DPT_Id)
);




-- TESISSEG.dbo.AS_Abogados definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_Abogados;

CREATE TABLE TESISSEG.dbo.AS_Abogados (
	SinNumID int NOT NULL,
	SinSer int NOT NULL,
	PRS_Id int NOT NULL,
	EmpID smallint DEFAULT 0 NULL,
	CONSTRAINT PK_Abogados PRIMARY KEY (SinNumID,SinSer,PRS_Id),
	CONSTRAINT FK_Abogados_PER FOREIGN KEY (PRS_Id) REFERENCES TESISSEG.dbo.AS_PERSONAS(PRS_Id)
);






-- TESISSEG.dbo.AS_DATOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_DATOS;

CREATE TABLE TESISSEG.dbo.AS_DATOS (
	DAT_Id int IDENTITY(1,1) NOT NULL,
	FORM_Id int NOT NULL,
	CAMP_Id int NOT NULL,
	OBJ_Id int NOT NULL,
	DAT_Valor text COLLATE Modern_Spanish_CI_AS NULL,
	DAT_Editable tinyint DEFAULT 0 NOT NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_DATOS PRIMARY KEY (DAT_Id),
	CONSTRAINT FK_DATOS_CAMPOS FOREIGN KEY (CAMP_Id) REFERENCES TESISSEG.dbo.AS_CAMPOS(CAMP_Id),
	CONSTRAINT FK_DATOS_FORMS FOREIGN KEY (FORM_Id) REFERENCES TESISSEG.dbo.AS_FORMS(FORM_Id)
);
 CREATE NONCLUSTERED INDEX DATOS_FORM_Id_CAMP_Id_index ON TESISSEG.dbo.AS_DATOS (  FORM_Id ASC  , CAMP_Id ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;



-- TESISSEG.dbo.AS_DISPOSITIVOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_DISPOSITIVOS;

CREATE TABLE TESISSEG.dbo.AS_DISPOSITIVOS (
	DIS_Id int IDENTITY(1,1) NOT NULL,
	Id int NOT NULL,
	DIS_Token varchar(255) COLLATE Modern_Spanish_CI_AS NOT NULL,
	DIS_Plataforma varchar(100) COLLATE Modern_Spanish_CI_AS NOT NULL,
	DIS_Version varchar(15) COLLATE Modern_Spanish_CI_AS NOT NULL,
	DIS_Uuid varchar(100) COLLATE Modern_Spanish_CI_AS NOT NULL,
	DIS_Cordova varchar(15) COLLATE Modern_Spanish_CI_AS NOT NULL,
	DIS_Modelo varchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	DIS_Fabricante varchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	DIS_EsVirtual tinyint NOT NULL,
	DIS_Serial varchar(100) COLLATE Modern_Spanish_CI_AS NOT NULL,
	DIS_Notificar tinyint DEFAULT 1 NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_DISPOSITIVOS PRIMARY KEY (DIS_Id),
	CONSTRAINT FK_DISPOSITIVOS_CLIENTES FOREIGN KEY (Id) REFERENCES TESISSEG.dbo.AS_CLIENTES(Id)
);


-- TESISSEG.dbo.AS_PROFESIONALES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_PROFESIONALES;

CREATE TABLE TESISSEG.dbo.AS_PROFESIONALES (
	SinNumID int NOT NULL,
	SinSer int NOT NULL,
	PRS_Id int NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PROFESIONALES_PK PRIMARY KEY (SinNumID,SinSer,PRS_Id,EmpID),
	CONSTRAINT FK_PROFESIONALES_PER FOREIGN KEY (PRS_Id) REFERENCES TESISSEG.dbo.AS_PERSONAS(PRS_Id)
);


-- TESISSEG.dbo.AS_RAMOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_RAMOS;

CREATE TABLE TESISSEG.dbo.AS_RAMOS (
	RAM_MyId int IDENTITY(1,1) NOT NULL,
	GRM_Id int NULL,
	RAM_TesisId char(5) COLLATE Modern_Spanish_CI_AI NOT NULL,
	RAM_Naturaleza smallint DEFAULT 8 NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_RAMOS PRIMARY KEY (RAM_MyId),
	CONSTRAINT FK_RAMOS_GRUPOSDERAMOS_RAMOS FOREIGN KEY (GRM_Id) REFERENCES TESISSEG.dbo.AS_GRUPOSDERAMOS(GRM_Id)
);


-- TESISSEG.dbo.AS_RUTAS_DENEGADAS_FUSION definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_RUTAS_DENEGADAS_FUSION;

CREATE TABLE TESISSEG.dbo.AS_RUTAS_DENEGADAS_FUSION (
	RUT_Id int IDENTITY(1,1) NOT NULL,
	ROL_Id int NOT NULL,
	RUT_Denegada nvarchar(250) COLLATE Modern_Spanish_CI_AS NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_RUTAS_DENEGADAS_FUSION PRIMARY KEY (RUT_Id),
	CONSTRAINT FK_RUTAS_DENEGADAS_FUSION_ROLES FOREIGN KEY (ROL_Id) REFERENCES TESISSEG.dbo.AS_ROLES(ROL_Id)
);


-- TESISSEG.dbo.AS_TESTIGOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_TESTIGOS;

CREATE TABLE TESISSEG.dbo.AS_TESTIGOS (
	SinNumID int NOT NULL,
	SinSer int NOT NULL,
	PRS_Id int NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT TESTIGOS_PK PRIMARY KEY (SinNumID,SinSer,PRS_Id,EmpID),
	CONSTRAINT FK_TESTIGOS_PER FOREIGN KEY (PRS_Id) REFERENCES TESISSEG.dbo.AS_PERSONAS(PRS_Id)
);


-- TESISSEG.dbo.AS_TRAMITADOR definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_TRAMITADOR;

CREATE TABLE TESISSEG.dbo.AS_TRAMITADOR (
	SinNumID int NOT NULL,
	SinSer int NOT NULL,
	PRS_Id int NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT TRAMITADOR_PK PRIMARY KEY (SinNumID,SinSer,PRS_Id,EmpID),
	CONSTRAINT FK_TRAMITADOR_PER FOREIGN KEY (PRS_Id) REFERENCES TESISSEG.dbo.AS_PERSONAS(PRS_Id)
);


-- TESISSEG.dbo.AS_USRPWD definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_USRPWD;

CREATE TABLE TESISSEG.dbo.AS_USRPWD (
	UPW_Id int IDENTITY(1,1) NOT NULL,
	USR_Id int NULL,
	UPW_DebeCambiarPass int NOT NULL,
	UPW_Baneado int NOT NULL,
	UPW_Suspendido int NOT NULL,
	UPW_Activo int NOT NULL,
	UPW_Avatar varchar(200) COLLATE Modern_Spanish_CI_AS NULL,
	ROL_Id int DEFAULT 1 NOT NULL,
	UPW_VerAgendaUsuarios tinyint DEFAULT 0 NOT NULL,
	UPW_EliminarSiniestros tinyint DEFAULT 0 NOT NULL,
	UPW_Asignar tinyint DEFAULT 0 NOT NULL,
	UPW_AsignarINC tinyint DEFAULT 0 NOT NULL,
	UPW_AsignarCM tinyint DEFAULT 0 NOT NULL,
	UPW_AsignarSIN tinyint DEFAULT 0 NOT NULL,
	UPW_AsignarOPT tinyint DEFAULT 0 NOT NULL,
	UPW_Perfil int DEFAULT 1 NOT NULL,
	COL_Id int NULL,
	UPW_Nombre varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	UPW_SmtpServer varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	UPW_SmtpPort varchar(6) COLLATE Modern_Spanish_CI_AS NULL,
	UPW_SmtpEncryption varchar(6) COLLATE Modern_Spanish_CI_AS NULL,
	UPW_SmtpUsername varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	UPW_SmtpPassword varchar(255) COLLATE Modern_Spanish_CI_AS NULL,
	UPW_SmtpFirma text COLLATE Modern_Spanish_CI_AS NULL,
	UPW_AvisosEmail tinyint DEFAULT 0 NOT NULL,
	UPW_AsignarREC tinyint DEFAULT 0 NOT NULL,
	UPW_UltimoAcceso datetime NULL,
	USR_IdTesis int NULL,
	ColID char(5) COLLATE Modern_Spanish_CI_AS NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK__USRPWD__49C3F6B7 PRIMARY KEY (UPW_Id),
	CONSTRAINT FK_USRPWD_ROLES FOREIGN KEY (ROL_Id) REFERENCES TESISSEG.dbo.AS_ROLES(ROL_Id)
);


-- TESISSEG.dbo.AS_COTIZACIONES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_COTIZACIONES;

CREATE TABLE TESISSEG.dbo.AS_COTIZACIONES (
	COT_ID int IDENTITY(1,1) NOT NULL,
	OPT_ID int NULL,
    CIA_ID char(5) COLLATE Modern_Spanish_CI_AI NULL,
	PRO_ID char(10) COLLATE Modern_Spanish_CI_AI NULL,
	POL_ID int NULL,
	COT_FECHASOLICITUDCORR datetime NULL,
	COT_FECHASOLICITUDCIA datetime NULL,
	COT_FECHARECEPCIONCIA datetime NULL,
	COT_FECHAENTREGACLT datetime NULL,
	COT_FECHACONTRATACION datetime NULL,
	COT_ESTADO tinyint NULL,
	COT_SITUACION tinyint NULL,
	COT_PRIMAANUAL money NULL,
	COT_TOTALRECIBOANUAL money NULL,
	COT_PRODUCTOCIA char(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	COT_COMENTARIOS text COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	COT_FC datetime NULL,
	COT_FM datetime NULL,
	USR_Id_FC int NULL,
	USR_Id_FM int NULL,
	COT_FechaEfecto datetime NULL,
	GES_Id int NULL,
	COT_Capital float NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_COTIZACIONES PRIMARY KEY (COT_ID),
	CONSTRAINT FK_OPORTUNIDADES_COTIZACIONES FOREIGN KEY (OPT_ID) REFERENCES TESISSEG.dbo.AS_OPORTUNIDADES(OPT_ID)
);
 CREATE NONCLUSTERED INDEX IND_COT_OPT_ID ON TESISSEG.dbo.AS_COTIZACIONES (  OPT_ID ASC  )
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ] ;

-- TESISSEG.dbo.AS_EMITIR definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_EMITIR;

CREATE TABLE TESISSEG.dbo.AS_EMITIR (
	EMI_Id int IDENTITY(577,1) NOT NULL,
	EMI_Agente varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	OPT_Id int NOT NULL,
	COT_Id int NOT NULL,
	EMI_FC datetime NOT NULL,
	EMI_Efecto datetime NULL,
	EMI_Nif varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	EMI_Banco varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	EMI_FormaPago varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	EMI_Observaciones varchar(MAX) COLLATE Modern_Spanish_CI_AS NULL,
	EMI_Compania varchar(50) COLLATE Modern_Spanish_CI_AS NULL,
	EMI_Prima money NULL,
	EMI_Emitida varchar(2) COLLATE Modern_Spanish_CI_AS NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_EMITIR2 PRIMARY KEY (EMI_Id),
	CONSTRAINT FK_OPORTUNIDADES_EMITIR FOREIGN KEY (OPT_Id) REFERENCES TESISSEG.dbo.AS_OPORTUNIDADES(OPT_Id),
	CONSTRAINT FK_COTIZACIONES_EMITIR FOREIGN KEY (COT_Id) REFERENCES TESISSEG.dbo.AS_COTIZACIONES(COT_Id)
	);

-- TESISSEG.dbo.AS_CAPITALES definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_CAPITALES;

CREATE TABLE TESISSEG.dbo.AS_CAPITALES (
	CPT_Id int IDENTITY(1,1) NOT NULL,
	COT_Id int NULL,
	CPT_Continente numeric(18,0) NULL,
	CPT_Contenido varchar(100) COLLATE Modern_Spanish_CI_AS NULL,
	CPT_RC int NULL,
	OldID int NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT PK_CAPITALES PRIMARY KEY (CPT_Id),
	CONSTRAINT FK_COTIZACIONES_CAPITALES FOREIGN KEY (COT_Id) REFERENCES TESISSEG.dbo.AS_COTIZACIONES(COT_Id)
);



-- TESISSEG.dbo.AS_LESIONADOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_LESIONADOS;

CREATE TABLE TESISSEG.dbo.AS_LESIONADOS (
	LES_Id int IDENTITY(1,1) NOT NULL,
	LES_Tipo smallint NULL,
	LES_ECivil smallint NULL,
	LES_Profesion varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	LES_Centro varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	LES_TelfCentro varchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	LES_FaxCentro varchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	LES_Departamento varchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	LES_Habitacion varchar(5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	LES_Lesiones varchar(80) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	LES_Secuelas varchar(80) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	LES_Observaciones text COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	LES_NIFCentro varchar(20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	SinNumID int NOT NULL,
	SinSer int NOT NULL,
	SinPerNum int NOT NULL,
	SIN_MyId int NOT NULL,
	PRS_CP varchar(5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRS_Apellido1 varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRS_Apellido2 varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRS_NIF varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRS_Sexo smallint NULL,
	PRS_Nacimiento datetime NULL,
	PRS_Direccion varchar(80) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	PRS_Localidad varchar(80) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	EmpID smallint DEFAULT 0 NULL,
	OldID int NULL,
	CONSTRAINT PK_LESIONADOS PRIMARY KEY (SinNumID,SinSer,LES_Id),
	CONSTRAINT FK_SINIESTROS_LESIONADOS FOREIGN KEY (SIN_MyId) REFERENCES TESISSEG.dbo.AS_SINIESTROS(SIN_MyId)
);

-- TESISSEG.dbo.AS_MAILS_ENVIADOS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_MAILS_ENVIADOS;

CREATE TABLE TESISSEG.dbo.AS_MAILS_ENVIADOS (
	MENV_Id int IDENTITY(1,1) NOT NULL,
	MENV_TipoObj int NOT NULL,
	OBJ_Id varchar(20) COLLATE Modern_Spanish_CI_AS NULL,
	Fusion_OBJ_Id char(30) COLLATE Modern_Spanish_CI_AS NULL,
	MENV_FC datetime NOT NULL,
	USR_Id int NULL,
	MENV_Para nvarchar(500) COLLATE Modern_Spanish_CI_AS NOT NULL,
	MENV_Asunto varchar(200) COLLATE Modern_Spanish_CI_AS NULL,
	MENV_Texto text COLLATE Modern_Spanish_CI_AS NULL,
	MENV_De nvarchar(50) COLLATE Modern_Spanish_CI_AS NOT NULL,
	MENV_Tipo int NOT NULL,
	MENV_Adjuntos nvarchar(100) COLLATE Modern_Spanish_CI_AS NULL,
	MENV_CCO nvarchar(500) COLLATE Modern_Spanish_CI_AS NULL,
	INC_Id int NULL,
	COL_Id int NULL,
	MENV_Perfil int DEFAULT 1 NOT NULL,
	UseID smallint NULL,
	ColID char(5) COLLATE Modern_Spanish_CI_AS NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_MAILS_ENVIADOS PRIMARY KEY (MENV_Id),
	CONSTRAINT FK_INCIDENCIAS_MAILS_ENVIADOS FOREIGN KEY (INC_Id) REFERENCES TESISSEG.dbo.AS_INCIDENCIAS(INC_Id)
);
CREATE NONCLUSTERED INDEX AS_MAILS_ENVIADOS_INC_Id_IDX ON dbo.AS_MAILS_ENVIADOS (  INC_Id ASC  , EmpID ASC  )  
	 WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	 ON [PRIMARY ];



-- TESISSEG.dbo.AS_NOTAS_OPT definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_NOTAS_OPT;

CREATE TABLE TESISSEG.dbo.AS_NOTAS_OPT (
	OPT_Id int NULL,
	NOT_Texto text COLLATE Modern_Spanish_CI_AS NULL,
	NOPT_Id int IDENTITY(1,1) NOT NULL,
	OldID int NULL,
	EmpID smallint DEFAULT 0 NULL,
	CONSTRAINT PK_NOTAS_OPT PRIMARY KEY (NOPT_Id),
	CONSTRAINT FK_OPORTUNIDADES_NOTAS_OPT FOREIGN KEY (OPT_Id) REFERENCES TESISSEG.dbo.AS_OPORTUNIDADES(OPT_Id)
);


-- TESISSEG.dbo.AS_NOTCOLTESIS definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_NOTCOLTESIS;

CREATE TABLE TESISSEG.dbo.AS_NOTCOLTESIS (
	NCOL_Id int NOT NULL,
	COL_Id int NOT NULL,
	NOTCOL_Leida tinyint NOT NULL,
	NOTCOL_FechaLeida datetime NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	CONSTRAINT NOTCOLTESIS_PK PRIMARY KEY (NCOL_Id,COL_Id,EmpID),
	CONSTRAINT FK_NOTIFICACIONES_COLABORADORES_NOTCOLTESIS FOREIGN KEY (NCOL_Id) REFERENCES TESISSEG.dbo.AS_NOTIFICACIONES_COLABORADORES(NCOL_Id)
);


-- TESISSEG.dbo.AS_OPCCAMP definition

-- Drop table

-- DROP TABLE TESISSEG.dbo.AS_OPCCAMP;

CREATE TABLE TESISSEG.dbo.AS_OPCCAMP (
	Id int IDENTITY(1,1) NOT NULL,
	CAMP_Id int NOT NULL,
	OPC_Id int NOT NULL,
	EmpID smallint DEFAULT 0 NOT NULL,
	OldID int NULL,
	CONSTRAINT PK_OPCCAMP PRIMARY KEY (Id),
	CONSTRAINT FK_OPCIONESCAMPO_OPCCAMP FOREIGN KEY (OPC_Id) REFERENCES TESISSEG.dbo.AS_OPCIONESCAMPO(OPC_Id),
	CONSTRAINT FK_CAMPOS_OPCCAMP FOREIGN KEY (CAMP_Id) REFERENCES TESISSEG.dbo.AS_CAMPOS(CAMP_Id)
);
