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
|
CREATE TABLE T1 (T1_PK INT NOT NULL, T1_T2 INT NOT NULL, T1_V1 VARCHAR(10), T1_V2 VARCHAR(10))
CREATE TABLE T2 (T2_PK INT NOT NULL, T2_T31 INT NOT NULL, T2_T32 INT NOT NULL, T2_V1 VARCHAR(10), T2_V2 VARCHAR(10))
CREATE TABLE T3 (T3_PK INT NOT NULL, T3_T4 INT NOT NULL, T3_V VARCHAR(10))
CREATE TABLE T4 (T4_PK INT NOT NULL,T4_V INT NOT NULL)
DECLARE @N INT
--Nombre d'enregistrement dans les tables (attention ce nombre est multiplié par 200 pour remplir certaines tables !!!)
SET @N=100
DECLARE @V INT
SET @V=1
WHILE (@V<=@N)
BEGIN
INSERT T4 (T4_PK,T4_V) VALUES (@V, @N-@V)
SET @V=@V+1
END
SET @V=1
DECLARE @R INT
SET @R=1
WHILE (@V<=200*@N)
BEGIN
IF @R>@N
BEGIN
SET @R=1
END
INSERT T3 (T3_PK, T3_T4, T3_V) VALUES (@V, @R, '----------')
SET @R=@R+1
SET @V=@V+1
END
SET @V=1
SET @R=1
WHILE (@V<=100*@N)
BEGIN
IF @R>@N
BEGIN
SET @R=1
END
INSERT T2 (T2_PK, T2_T31, T2_T32, T2_V1, T2_V2) VALUES (@V,@V,@V+@N,'----------','----------')
SET @R=@R+1
SET @V=@V+1
END
SET @V=1
SET @R=1
WHILE (@V<=100*@N)
BEGIN
IF @R>@N
BEGIN
SET @R=1
END
INSERT T1 (T1_PK, T1_T2, T1_V1, T1_V2) VALUES (@V,@V,'----------','----------')
SET @R=@R+1
SET @V=@V+1
END
ALTER TABLE T1 ADD CONSTRAINT PK_T1 PRIMARY KEY CLUSTERED (T1_PK)
ALTER TABLE T2 ADD CONSTRAINT PK_T2 PRIMARY KEY CLUSTERED (T2_PK)
ALTER TABLE T3 ADD CONSTRAINT PK_T3 PRIMARY KEY CLUSTERED (T3_PK)
ALTER TABLE T4 ADD CONSTRAINT PK_T4 PRIMARY KEY CLUSTERED (T4_PK)
ALTER TABLE T1 ADD CONSTRAINT FK_T1_T2 FOREIGN KEY (T1_T2) REFERENCES T2 (T2_PK)
ALTER TABLE T2 ADD CONSTRAINT FK_T2_T31 FOREIGN KEY (T2_T31) REFERENCES T3 (T3_PK)
ALTER TABLE T2 ADD CONSTRAINT FK_T2_T32 FOREIGN KEY (T2_T32) REFERENCES T3 (T3_PK)
ALTER TABLE T3 ADD CONSTRAINT FK_T3_T4 FOREIGN KEY (T3_T4) REFERENCES T4 (T4_PK)
CREATE NONCLUSTERED INDEX INC_T1_T2 ON T1 (T1_T2)
CREATE NONCLUSTERED INDEX INC_T2_T31 ON T2 (T2_T31)
CREATE NONCLUSTERED INDEX INC_T2_T32 ON T2 (T2_T32)
CREATE NONCLUSTERED INDEX INC_T3_T4 ON T3 (T3_T4)
CREATE NONCLUSTERED INDEX INC_T3_V ON T3 (T3_V)
CREATE NONCLUSTERED INDEX INC_T4_V ON T4 (T4_V) |
Partager