Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Best Approach for Updating Bridge Table

Author  Topic 

dewacorp.alliances

452 Posts

Posted - 2009-02-01 : 03:38:51
Hi there

I have a bridge table in SQL Server 2005 called CaseCaseTypes which has the table strcutre as follow:
1. CaseCaseTypeID INT IsIDentity=YES
2. CaseID INT
3. CaseTypeID INT

Due to I am using ORM (Object Relation Mapping) from EntitySpace, I have to create an IDENTITY for the bridge table.

Obviouslay I have Cases table (CaseID, CaseName, etc) and CaseTypes table(CaseTypeID, CaseTypeName etc).

If you have data already let say and you have a check box for CaseType.
CaseCaseTypeID, CaseID, CaseTypeID
1, 1, 1
2, 1, 2
3, 1, 3

So you populate all checkbox where CaseID = 1 for instance and comes out 1,2,3. Ley say the user change to just 1, 3. What do you do in this case when you save the data?

Do you delete all entries where CaseID = 1 and do the insert CaseTypeID = 1 and 3 (1st approach)? Or you check the ID and if it's there updated it and if it's not ... inserted it (2nd approach)?

I usually the first approach but due to I have Identity in this table and it' inserting new identity everytime you save the data.

Thanks

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2009-02-01 : 06:16:18
That's the trouble with this ORM stuff - you need to introduce crap into your data model you don't need and doesn't relate to anything meaningful. Your PK is case & type ID and thats it.
If you have loads of inserts then you will get a hotspot on your table around the ID which might cause issues, so I would update existing rows to spread the contention around a bit. Without ORM I would say just delete the ones you don't use. As ever though, try both & see what works for you.
Go to Top of Page
   

- Advertisement -