1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
-- Creating Table
use [IBatisNet]
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Others]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
drop table [dbo].[Others]
END
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[A]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
drop table [dbo].[A]
END
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[B]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
drop table [dbo].[B]
END
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[C]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
drop table [dbo].[C]
END
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[D]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
drop table [dbo].[D]
END
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[E]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
drop table [dbo].[E]
END
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[F]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
drop table [dbo].[F]
END
CREATE TABLE [dbo].[Others] (
[Other_Int] [int] NULL ,
[Other_Long] [BigInt] NULL,
[Other_Bit] [Bit] NOT NULL DEFAULT (0),
[Other_String] [varchar] (32) NOT NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[F] (
[ID] [varchar] (50) NOT NULL ,
[F_Libelle] [varchar] (50) NULL ,
CONSTRAINT [PK_F] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[E] (
[ID] [varchar] (50) NOT NULL ,
[E_Libelle] [varchar] (50) NULL ,
CONSTRAINT [PK_E] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[D] (
[ID] [varchar] (50) NOT NULL ,
[D_Libelle] [varchar] (50) NULL ,
CONSTRAINT [PK_D] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[C] (
[ID] [varchar] (50) NOT NULL ,
[C_Libelle] [varchar] (50) NULL ,
CONSTRAINT [PK_C] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[B] (
[ID] [varchar] (50) NOT NULL ,
[C_ID] [varchar] (50) NULL ,
[D_ID] [varchar] (50) NULL ,
[B_Libelle] [varchar] (50) NULL ,
CONSTRAINT [PK_B] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY] ,
CONSTRAINT [FK_B_C] FOREIGN KEY
(
[C_ID]
) REFERENCES [C] (
[ID]
),
CONSTRAINT [FK_B_D] FOREIGN KEY
(
[D_ID]
) REFERENCES [D] (
[ID]
)
) ON [PRIMARY]
CREATE TABLE [dbo].[A] (
[Id] [varchar] (50) NOT NULL ,
[B_ID] [varchar] (50) NULL ,
[E_ID] [varchar] (50) NULL ,
[F_ID] [varchar] (50) NULL ,
[A_Libelle] [varchar] (50) NULL
CONSTRAINT [PK_A] PRIMARY KEY CLUSTERED
(
[Id]
) ON [PRIMARY] ,
CONSTRAINT [FK_A_B] FOREIGN KEY
(
[B_ID]
) REFERENCES [B] (
[ID]
),
CONSTRAINT [FK_A_E] FOREIGN KEY
(
[E_ID]
) REFERENCES [E] (
[ID]
),
CONSTRAINT [FK_A_F] FOREIGN KEY
(
[F_ID]
) REFERENCES [F] (
[ID]
)
) ON [PRIMARY]
-- Creating Test Data
INSERT INTO [dbo].[Others] VALUES(1, 8888888, 0, 'Oui');
INSERT INTO [dbo].[Others] VALUES(2, 9999999999, 1, 'Non');
INSERT INTO [dbo].[F] VALUES('f', 'fff');
INSERT INTO [dbo].[E] VALUES('e', 'eee');
INSERT INTO [dbo].[D] VALUES('d', 'ddd');
INSERT INTO [dbo].[C] VALUES('c', 'ccc');
INSERT INTO [dbo].[B] VALUES('b', 'c', null, 'bbb');
INSERT INTO [dbo].[A] VALUES('a', 'b', 'e', null, 'aaa');
|