I'm building an insurance database and I need some help with best practice on fast quering data.
Let's say I have three insurance types ... Car, Home and Travel.
Common for all three types, I have the "Insurance" table:
[dbo].[Insurance] (
[InsuranceID] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[CustomerID] [uniqueidentifier] NOT NULL,
[CreatedDate] [datetime] NOT NULL
)
And then I have the three insurance types:
[dbo].[InsuranceCar] (
[InsuranceCarID] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[InsuranceID] [uniqueidentifier] NOT NULL,
[Model] [uniqueidentifier] NOT NULL
)
[dbo].[InsuranceHome] (
[InsuranceHomeID] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[InsuranceID] [uniqueidentifier] NOT NULL,
[Address] [uniqueidentifier] NOT NULL
)
[dbo].[InsuranceTravel] (
[InsuranceTravelID] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[InsuranceID] [uniqueidentifier] NOT NULL,
[Destination] [uniqueidentifier] NOT NULL
)
All three insurance types have an "key search field" that I use for quering an insurance - in "Car" it is "Model", in "Home" it is "Address" and in "Travel" it is "Destination".
So the way I have solved it, is to create a "_Search" column in the "Insurance" table ...
[dbo].[Insurance] (
[InsuranceID] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[CustomerID] [uniqueidentifier] NOT NULL,
[CreatedDate] [datetime] NOT NULL,
[_Search] [nvarchar(MAX)] NULL
)
... and when any of the insurance type table rows is created/updated, then I copy the "key seach field" from the incurance type table into my "Insurance" tables "_Search" column (using trigger).
This way I can quickly query any key fields from the three insurance type tables by quering the "_Search" field in the "Insurance" table.
Problem is that it takes up more space in the database to do it like this.
Any better way to do this? Best practice?
Thanks.