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
|
CREATE TABLE [dbo].[_tblTst_Classe](
IdClasse [int] NOT NULL,
Code [char](2) NULL,
CONSTRAINT [PK__tblTst_Classe] PRIMARY KEY CLUSTERED
(
[IdClasse] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[_tbltst_ClasseMagHisto](
[IdHisto] [int] NOT NULL,
[DTMutation] [datetime] NOT NULL,
[IdMag] [int] NOT NULL,
[IdClasse] [int] NOT NULL,
CONSTRAINT [PK__tbltst_ClasseMagHisto] PRIMARY KEY CLUSTERED
(
[IdHisto] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[_TblTst_Mag](
[IdMag] [int] NOT NULL,
[NomMag] [varchar](10) NOT NULL,
CONSTRAINT [PK__TblTst_Mag] PRIMARY KEY CLUSTERED
(
[IdMag] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[_tbltst_ClasseMagHisto] WITH CHECK ADD CONSTRAINT [FK__tbltst_ClasseMagHisto__tblTst_Classe] FOREIGN KEY([IdClasse])
REFERENCES [dbo].[_tblTst_Classe] ([IdClasse])
GO
ALTER TABLE [dbo].[_tbltst_ClasseMagHisto] CHECK CONSTRAINT [FK__tbltst_ClasseMagHisto__tblTst_Classe]
GO
ALTER TABLE [dbo].[_tbltst_ClasseMagHisto] WITH CHECK ADD CONSTRAINT [FK__tbltst_ClasseMagHisto__TblTst_Mag] FOREIGN KEY([IdMag])
REFERENCES [dbo].[_TblTst_Mag] ([IdMag])
GO
ALTER TABLE [dbo].[_tbltst_ClasseMagHisto] CHECK CONSTRAINT [FK__tbltst_ClasseMagHisto__TblTst_Mag]
GO
---------------
--DATA
--------------
INSERT INTO _TblTst_Mag(IdMag, NomMag)
VALUES (1,'M1'),(2,'M2'),(3,'M3'),(4,'M4')
GO
INSERT INTO _tbltst_classe(IdClasse, Code)
VALUES (1,'C1'),(2,'C2'),(3,'C3'),(4,'C4')
GO
INSERT INTO _tbltst_ClasseMagHisto(IdHisto, DtMutation,IdMag,IdClasse)
VALUES (1 ,'20120101',1,1)
,(2 ,'20120201',2,1)
,(3 ,'20120301',2,2)
,(4 ,'20120101',3,4)
,(5 ,'20120201',3,3)
,(6 ,'20120401',3,2)
,(7 ,'20120301',3,1)
,(8 ,'20120101',4,3)
,(9 ,'20120601',4,1)
,(10,'20120201',4,3) |
Partager