Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Name Value Pair - Part II


Name Value Pair - Part II

Author
Message
Teshome-283915
Teshome-283915
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 680
Comments posted to this topic are about the item Name Value Pair - Part II
Christian Gräfe
Christian Gräfe
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 309
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
marcosc
marcosc
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 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/)
Teshome-283915
Teshome-283915
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 680
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
Teshome-283915
Teshome-283915
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 680
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.
marcosc
marcosc
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 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.
Teshome-283915
Teshome-283915
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 680
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.
Mauve
Mauve
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1246 Visits: 2049
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.
Cade Roux
Cade Roux
SSC-Enthusiastic
SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)

Group: General Forum Members
Points: 128 Visits: 491
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.
SuperDBA-207096
SuperDBA-207096
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1477 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?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search