Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

Name Value Pair - Part II Expand / Collapse
Author
Message
Posted Saturday, May 17, 2008 5:00 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 16, 2014 5:26 AM
Points: 25, Visits: 548
Comments posted to this topic are about the item Name Value Pair - Part II
Post #502551
Posted Monday, May 19, 2008 5:36 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, October 13, 2014 4:23 AM
Points: 2, Visits: 258
Cool approach for dynamic columns,

How can column names added dynamically instead of hardcoding it!
Is it possible via a sysname data type or is it only possible via dynamic sql.

regards Christian
Post #502715
Posted Monday, May 19, 2008 6:46 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, October 21, 2010 9:50 AM
Points: 24, Visits: 41
Hi, I don't think this is a cool design. And if you read the final paragraph you'll see that this is an article against this design and not for it.
In databases and programs column names are important and are the main link between then. How can you show the name of the customer if you have to guess the column name ? You need to assume its name, so you should "hardcore" the column name or your reports and application will be completly unestable (sometimes data will be shown and other not just because a programmer confused the column name).
Just an opinion. Thanks, Marcos.

---
Need to know everything about the DB structtre ? navigate it with Nautilus (http://sourceforge.net/projects/nautilus/)
Post #502745
Posted Monday, May 19, 2008 7:06 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 16, 2014 5:26 AM
Points: 25, Visits: 548
If you see below and the name part is not in the lookup table, it will add to it automatically. I have included the script with the article for you to look into it.

Regards
CREATE procedure [dbo].[InsertNameValuePair]
@CustomerId int,
@Name nvarchar(100),
@value nvarchar(max)
as
set nocount on
declare @pairNameId smallint, @partitionId int
if exists (select top 1 PairNameId from dbo.PairNames where PairName like @Name)
begin
select @pairNameId = PairNameId
from dbo.PairNames where pairname = @Name
end
else
begin
insert into dbo.PairNames(PairName)
values (@Name)
select @pairNameId = scope_identity()
end

set @partitionId = @customerId%4 + 1
insert into nvp(CustomerId, partitionId, PairNameId, PairValue)
values (@customerId, @partitionId, @pairNameId, @value)

go
Post #502768
Posted Monday, May 19, 2008 7:11 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 16, 2014 5:26 AM
Points: 25, Visits: 548
Hi Markos,

As you said it is not a cool design but for the situation that was described it
was the best approch to take.

The final paragraph also shows that to use name value pair for the problem that was described in this article is not good.

How can you show the name of the customer if you have to guess the column name ?


With name value pair you need to know the name to find the pair value. I am not sure what you mean here.
Post #502774
Posted Monday, May 19, 2008 7:41 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, October 21, 2010 9:50 AM
Points: 24, Visits: 41
I mean this: if the program and the reports all need to know the property name, it's the same thing as knowing the column name of the table. So I prefer the traditional design.
Besides that, adding a column isn't something difficult, so we should not be lazy about that.
Besides that, you can use foreign keys when a column valus needs options (example: single, married, divorced, etc.). You can't do that with property-values pairs.
Besides that, you can be sure that a requiered value is present using a "not null" column. That's dificult to achieve with a property-value design.

Regards, Marcos.
Post #502798
Posted Monday, May 19, 2008 8:07 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 16, 2014 5:26 AM
Points: 25, Visits: 548
Hi markos,


marcosc (5/19/2008)
I mean this: if the program and the reports all need to know the property name, it's the same thing as knowing the column name of the table. So I prefer the traditional design.
Besides that, adding a column isn't something difficult, so we should not be lazy about that.
Besides that, you can use foreign keys when a column valus needs options (example: single, married, divorced, etc.). You can't do that with property-values pairs.
Besides that, you can be sure that a requiered value is present using a "not null" column. That's dificult to achieve with a property-value design.

Regards, Marcos.


You are right in this regard. I am not a fun of name value pair either. I am just sharing my experience and how I managed to get the system up and running without holding the project. I have never used name value pair design for this type of problem. EAV doesn't lend itself for this particular problem.
Post #502818
Posted Monday, May 19, 2008 9:30 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 7:50 AM
Points: 1,186, Visits: 1,977
This sort of data-driven attribute-value pairs in a relational database quickly goes bad. I've seen too many attempts at this with disastrous results. In particular, when either querying the data with filtering and/or actually returning the data to the consumer (application).

For an interesting read on one such attempt, see the following:
http://www.simple-talk.com/opinion/opinion-pieces/bad-carma/



(PHB) I think we should build an SQL database. (Dilbert) What color do you want that database? (PHB) I think mauve has the most RAM.
Post #502908
Posted Monday, May 19, 2008 10:12 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, September 4, 2014 8:26 AM
Points: 109, Visits: 490
I love this:

"The suggestion was right in the long run, but as I have mentioned previously, the project had gone so far it was very difficult to revert back. So, I had to come up with a solution where it is possible to go live with the already developed solution and stil improve performance."

There's always enough time to do it over, but not enough time to do it right.

I've learned that when business people tell me that getting to market is more important than running their business well, I'm only there to postpone the inevitable business failure. And when they tell me that they are the business people and I need to let them do what they are good at - they don't even deserve that life preserver.
Post #502938
Posted Monday, May 19, 2008 10:23 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Wednesday, January 2, 2013 12:15 PM
Points: 1,443, Visits: 711
Seems like the 'right' answer is to redesign the DB.

Having inherited designs like this most likely the reason for the design is to provided the flexibility to add new attributes without re-coding.

Has anyone considered using an xml based approach to replace the E-A-V model?
Post #502948
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse