CREATE TABLE [dbo].[Device_Groups]
(
[DeviceID] [int] NOT NULL,
[GroupID] [int] NOT NULL,
[StartDate] [datetime] NOT NULL,
[EndDate] [datetime] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Device_Groups] ADD CONSTRAINT [PK_Device_Groups_DeviceID_GroupID] PRIMARY KEY CLUSTERED ([DeviceID], [GroupID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Device_Groups] ADD CONSTRAINT [FK_Device_Groups_DeviceID_Device_DeviceID] FOREIGN KEY ([DeviceID]) REFERENCES [dbo].[Device] ([DeviceID]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Device_Groups] ADD CONSTRAINT [FK_Device_Groups_GroupID_Groups_GroupID] FOREIGN KEY ([GroupID]) REFERENCES [dbo].[Groups] ([GroupID])
GO