I'm trying to avoid creating a new table. Here's the scenario:
I have an existing table with the following structure...
The primary key for this table is a composite key:
IDSTR is a user-defined type (varchar(20)).
I have a requirement to give the ability to set special pricing on a higher level than DoctorID (practice groups).
If I add my PracticeGroupID (it's an INT) field to this table, both it and DoctorID would have to be nullable - no problem, except that I won't be able to use either of these fields in a composite primary key anymore.
I can add a CHECK constraint to enforce that records have either a DoctorID or a PracticeGroupID, but I'm trying to find a way to keep duplicate records out from the database side as opposed to the front end.
The only thing I can think of would be a Type field (likely and Integer, set to 0 or 1) to delineate between special pricing for a doctor or a practice group. Then my composite key would look like:
I guess this would work, but I'd like to get some other opinions.
Thanks in advance for any suggestions.
-dave
I have an existing table with the following structure...
Code:
CREATE TABLE [dbo].[SpPrices] (
[DoctorID] [varchar] (20) NOT NULL ,
[ProductID] [IDSTR] NOT NULL ,
[Price] [MONEY] NULL,
[FacilityID] [IDSTR] NOT NULL,
) ON [PRIMARY]
The primary key for this table is a composite key:
Code:
ALTER TABLE [dbo].[SpPrices] ADD CONSTRAINT [SpPrices_DoctorProductFacility] PRIMARY KEY CLUSTERED
(
[DoctorID],
[ProductID],
[FacilityID]
) ON [PRIMARY]
IDSTR is a user-defined type (varchar(20)).
I have a requirement to give the ability to set special pricing on a higher level than DoctorID (practice groups).
If I add my PracticeGroupID (it's an INT) field to this table, both it and DoctorID would have to be nullable - no problem, except that I won't be able to use either of these fields in a composite primary key anymore.
I can add a CHECK constraint to enforce that records have either a DoctorID or a PracticeGroupID, but I'm trying to find a way to keep duplicate records out from the database side as opposed to the front end.
The only thing I can think of would be a Type field (likely and Integer, set to 0 or 1) to delineate between special pricing for a doctor or a practice group. Then my composite key would look like:
Code:
ALTER TABLE [dbo].[SpPrices] ADD CONSTRAINT [SpPrices_ProductFacilityType] PRIMARY KEY CLUSTERED
(
[ProductID],
[FacilityID],
[Type]
) ON [PRIMARY]
I guess this would work, but I'd like to get some other opinions.
Thanks in advance for any suggestions.
-dave