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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
| -- *************************************************************************************************
--
-- CREATE NEW DATABASE
--
-- *************************************************************************************************
USE master ;
GO
-- Remove previous DB instance
DROP DATABASE IF EXISTS "GestionCheptel"
GO
-- Create new database - destination folder MUST EXIST
CREATE DATABASE "GestionCheptel"
ON PRIMARY
( NAME = 'GestionCheptel_data',
FILENAME = 'C:\Users\Public\GestionCheptel.mdf',
SIZE = 2MB,
FILEGROWTH = 5 )
LOG ON
( NAME = 'GestionCheptel_log',
FILENAME = 'C:\Users\Public\GestionCheptel.ldf',
SIZE = 2MB,
FILEGROWTH = 5MB ) ;
GO
-- Create local database user
use "GestionCheptel"
go
exec sp_configure 'contained database authentication', 1
go
reconfigure
go
alter database "GestionCheptel"
set containment = partial
go
CREATE USER Test WITH PASSWORD = '$Password1234'
go
-- *************************************************************************************************
--
-- FILL DATABASE
--
-- *************************************************************************************************
USE [GestionCheptel]
GO
-- Clean up to avoid duplicates
-- DROP TABLE IF EXISTS Breeder;
-- DROP TABLE IF EXISTS Animal;
-- DROP TABLE IF EXISTS GenealogyLink;
-- GO
CREATE TABLE Breeder ([Id] int IDENTITY(1,1) NOT NULL,
[Affix] varchar(max) NULL,
[Affix_Prefix] bit NOT NULL,
[Affix_Creation] date NULL,
[LastName] varchar(255),
[FirstName] varchar(255),
[Address] varchar(255),
[City] varchar(255)
PRIMARY KEY (Id)
);
CREATE TABLE Animal([Id] int IDENTITY(1,1) NOT NULL,
[BreederId] int NULL,
[Name] varchar(max) NULL,
[Male] bit NOT NULL,
[NickName] varchar(max) NULL,
[BirthDate] date NULL,
[DeathDate] date NULL,
PRIMARY KEY (Id),
FOREIGN KEY (BreederId) REFERENCES Breeder(Id)
) AS NODE;
CREATE TABLE GenealogyLink (Father bit) AS EDGE;
-- Liste d'éleveurs
Set Identity_Insert dbo.Breeder On;
Insert dbo.Breeder(Id, Affix, Affix_Prefix) Values
(1, '(inconnu)', 0),
(2, 'Des garrigues du loup de canebas', 0),
(3, 'De Dan Jourdain', 0),
(4, 'Des rêves de neige', 0),
(5, 'De la Baisse de l''Eveillat', 0),
(6, 'Des Loups de l''antartic', 0),
(7, 'Of Dawson City', 0),
(8, 'Tundrafoot''s', 1),
(9, 'Kossok''s', 1),
(10, 'Du loup sibérien', 0),
(11, 'Snowmist''s', 1),
(12, 'Innisfree''s', 1),
(13, 'Of Watson Lake', 0);
go
Set Identity_Insert dbo.Breeder Off;
-- Liste d'animaux
Set Identity_Insert dbo.Animal On;
Insert dbo.Animal(Id, BreederId, Name, Male, NickName) Values
(1, 12, 'Urane', 0, 'Ruru'),
(2, 2, 'Morion', 1, NULL),
(3, 3, 'J''Sirène', 0, 'Sissi'),
(4, 4, 'Ice pack', 1, NULL),
(5, 5, 'Eikinah', 0, NULL),
(6, 6, 'Goodson', 1, 'Goody'),
(7, 7, 'F''Sheree Jones', 0, NULL),
(8, 8, 'Devil Indeskyz', 1, NULL),
(9, 4, 'Enoukye', 0, NULL),
(10,1, 'Brixo', 1, NULL),
(11,5, 'Uhlania', 0, NULL),
(12,9, 'Gold Nugget', 1, NULL),
(13,10, 'Indiana', 0, NULL),
(14,11, 'Cedarstone Phaedra', 0, NULL),
(15,1, 'Blackoak''s Crescendo cd', 1, NULL),
(16,1, 'Isa-Tai''s Ringo of sno-den', 1, NULL),
(17,1, 'Lobo''s Big boy', 1, NULL),
(18,1, 'Anuk', 1, NULL),
(19,9, 'Cinndar fella', 1, NULL),
(20,12, 'Shadow royal', 1, NULL),
(21,1, 'Ihalmuit''s Fair dawn', 0, NULL),
(22,11, 'Another sheila', 0, NULL),
(23,1, 'Odessa', 0, NULL),
(24,9, 'Good as gold', 0, NULL),
(25,11, 'Artic dawn', 0, NULL),
(26,11, 'Danielle', 0, NULL);
go
Set Identity_Insert dbo.Animal Off;
Insert into GenealogyLink ($to_id,$from_id, Father) values
-- Urane
(
(select $node_id from dbo.Animal where Id= 1 ),
(select $node_id from dbo.Animal where Id= 3 ),
0
),
(
(select $node_id from dbo.Animal where Id= 1 ),
(select $node_id from dbo.Animal where Id= 2 ),
1
),
-- Morion
(
(select $node_id from dbo.Animal where Id= 2 ),
(select $node_id from dbo.Animal where Id= 5 ),
0
),
(
(select $node_id from dbo.Animal where Id= 2 ),
(select $node_id from dbo.Animal where Id= 4 ),
1
),
-- Sirene
(
(select $node_id from dbo.Animal where Id= 3 ),
(select $node_id from dbo.Animal where Id= 7 ),
0
),
(
(select $node_id from dbo.Animal where Id= 3 ),
(select $node_id from dbo.Animal where Id= 6 ),
1
),
-- Ice pack
(
(select $node_id from dbo.Animal where Id= 4 ),
(select $node_id from dbo.Animal where Id= 9 ),
0
),
(
(select $node_id from dbo.Animal where Id= 4 ),
(select $node_id from dbo.Animal where Id= 8 ),
1
),
-- Eikinah
(
(select $node_id from dbo.Animal where Id= 5 ),
(select $node_id from dbo.Animal where Id= 11 ),
0
),
(
(select $node_id from dbo.Animal where Id= 5 ),
(select $node_id from dbo.Animal where Id= 10 ),
1
),
-- Goodson
(
(select $node_id from dbo.Animal where Id= 6 ),
(select $node_id from dbo.Animal where Id= 13 ),
0
),
(
(select $node_id from dbo.Animal where Id= 6 ),
(select $node_id from dbo.Animal where Id= 12 ),
1
),
-- Sheree
(
(select $node_id from dbo.Animal where Id= 7 ),
(select $node_id from dbo.Animal where Id= 14 ),
0
),
(
(select $node_id from dbo.Animal where Id= 7 ),
(select $node_id from dbo.Animal where Id= 10 ),
1
),
-- Tundrafoot's Devil Indeskyz
(
(select $node_id from dbo.Animal where Id= 8 ),
(select $node_id from dbo.Animal where Id= 21 ),
0
),
(
(select $node_id from dbo.Animal where Id= 8 ),
(select $node_id from dbo.Animal where Id= 15 ),
1
),
-- Enoukye
(
(select $node_id from dbo.Animal where Id= 9 ),
(select $node_id from dbo.Animal where Id= 22 ),
0
),
(
(select $node_id from dbo.Animal where Id= 9 ),
(select $node_id from dbo.Animal where Id= 16 ),
1
),
-- Brixo
(
(select $node_id from dbo.Animal where Id= 10 ),
(select $node_id from dbo.Animal where Id= 22 ),
0
),
(
(select $node_id from dbo.Animal where Id= 10 ),
(select $node_id from dbo.Animal where Id= 17 ),
1
),
-- Uhlania
(
(select $node_id from dbo.Animal where Id= 11 ),
(select $node_id from dbo.Animal where Id= 23 ),
0
),
(
(select $node_id from dbo.Animal where Id= 11 ),
(select $node_id from dbo.Animal where Id= 18 ),
1
),
-- Kossok''s Gold Nugget
(
(select $node_id from dbo.Animal where Id= 12 ),
(select $node_id from dbo.Animal where Id= 24 ),
0
),
(
(select $node_id from dbo.Animal where Id= 12 ),
(select $node_id from dbo.Animal where Id= 19 ),
1
),
-- Indiana du loup sibérien
(
(select $node_id from dbo.Animal where Id= 13 ),
(select $node_id from dbo.Animal where Id= 25 ),
0
),
(
(select $node_id from dbo.Animal where Id= 13 ),
(select $node_id from dbo.Animal where Id= 18 ),
1
),
-- Snowmist''s Cedarstone Phaedra
(
(select $node_id from dbo.Animal where Id= 14 ),
(select $node_id from dbo.Animal where Id= 26 ),
0
),
(
(select $node_id from dbo.Animal where Id= 14 ),
(select $node_id from dbo.Animal where Id= 20 ),
1
);
go |
Partager