· 8 years ago · Mar 06, 2018, 06:26 PM
1SET ANSI_NULLS ON
2GO
3SET QUOTED_IDENTIFIER ON
4GO
5IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ReferenciasTipos_T]') AND type in (N'U'))
6BEGIN
7CREATE TABLE [dbo].[ReferenciasTipos_T](
8 [TipID] [int] IDENTITY(1,1) NOT NULL,
9 [TipNombre] [nvarchar](200) NOT NULL,
10 [TipDescripcion] [nvarchar](500) NULL,
11 [TipIsNotas] [char](1) NOT NULL CONSTRAINT [DF_ReferenciasTipos_T_TipIsNotas] DEFAULT ('N'),
12 [TipTituloNotas] [nvarchar](50) NULL,
13 [TipTituloNotaUnaLinea] [nvarchar](100) NULL,
14 [TipIsNotaUnaLinea] [char](1) NOT NULL CONSTRAINT [DF_ReferenciasTipos_T_TipIsNotaUnaLinea] DEFAULT ('N'),
15 [TipPadreID] [int] NULL,
16 [TipSystemUser] [char](1) NULL,
17 [Creacion] [datetime] NOT NULL CONSTRAINT [DF_ReferenciasTipos_T_Creado] DEFAULT (getdate()),
18 [Modificacion] [datetime] NOT NULL CONSTRAINT [DF_ReferenciasTipos_T_Modificado] DEFAULT (getdate()),
19 [Creacion_UsrID] [int] NULL,
20 [DeletedDate] [datetime] NULL,
21 CONSTRAINT [PK_ReferenciasTipos_T] PRIMARY KEY CLUSTERED
22(
23 [TipID] ASC
24)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
25) ON [PRIMARY]
26END
27GO
28SET ANSI_NULLS ON
29GO
30SET QUOTED_IDENTIFIER ON
31GO
32IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ReferenciasValores_T]') AND type in (N'U'))
33BEGIN
34CREATE TABLE [dbo].[ReferenciasValores_T](
35 [ValorID] [int] IDENTITY(1,1) NOT NULL,
36 [TipID] [int] NOT NULL,
37 [ParentID] [int] NULL,
38 [Descripcion] [nvarchar](200) NOT NULL,
39 [Orden] [int] NULL CONSTRAINT [DF_ReferenciasValores_T_Orden] DEFAULT ((0)),
40 [Notas] [text] NULL,
41 [NotaUnaLinea] [nvarchar](50) NULL,
42 [Creacion] [datetime] NOT NULL CONSTRAINT [DF_ReverenciasValores_Creado] DEFAULT (getdate()),
43 [Modificacion] [datetime] NOT NULL CONSTRAINT [DF_ReverenciasValores_Modificado] DEFAULT (getdate()),
44 [Creacion_UsrID] [int] NULL,
45 [Comp_ID] [int] NULL,
46 [DeletedDate] [datetime] NULL,
47 CONSTRAINT [PK_ReverenciasValores] PRIMARY KEY CLUSTERED
48(
49 [ValorID] ASC
50)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
51) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
52END
53GO
54IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ReferenciasTipos_T_ReferenciasTipos_T]') AND parent_object_id = OBJECT_ID(N'[dbo].[ReferenciasTipos_T]'))
55ALTER TABLE [dbo].[ReferenciasTipos_T] WITH CHECK ADD CONSTRAINT [FK_ReferenciasTipos_T_ReferenciasTipos_T] FOREIGN KEY([TipPadreID])
56REFERENCES [dbo].[ReferenciasTipos_T] ([TipID])
57GO
58IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ReferenciasValores_T_Usuarios_T]') AND parent_object_id = OBJECT_ID(N'[dbo].[ReferenciasValores_T]'))
59ALTER TABLE [dbo].[ReferenciasValores_T] WITH CHECK ADD CONSTRAINT [FK_ReferenciasValores_T_Usuarios_T] FOREIGN KEY([Creacion_UsrID])
60REFERENCES [dbo].[Usuarios_T] ([UsrID])
61GO
62IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ReverenciasValores_ReferenciasTipos_T]') AND parent_object_id = OBJECT_ID(N'[dbo].[ReferenciasValores_T]'))
63ALTER TABLE [dbo].[ReferenciasValores_T] WITH CHECK ADD CONSTRAINT [FK_ReverenciasValores_ReferenciasTipos_T] FOREIGN KEY([TipID])
64REFERENCES [dbo].[ReferenciasTipos_T] ([TipID])
65GO
66IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ReverenciasValores_ReverenciasValores]') AND parent_object_id = OBJECT_ID(N'[dbo].[ReferenciasValores_T]'))
67ALTER TABLE [dbo].[ReferenciasValores_T] WITH CHECK ADD CONSTRAINT [FK_ReverenciasValores_ReverenciasValores] FOREIGN KEY([ParentID])
68REFERENCES [dbo].[ReferenciasValores_T] ([ValorID])