r/DatabaseHelp • u/NotSeanPlott • Feb 21 '17
What is faster? Does it matter?
Hello Again everyone!
I have a question about ways to query: http://imgur.com/a/X1nvt
That links to a example table setup and ERD.
The database stores either the AccountID or ContactID, this validation is done by the application I assume.
Again I'm a noob and I'm curious which approach I should take. I need to access either the Contacts Fullname or the Accounts Name.
I believe have two options, either use:
- Case
When order.CustomerType = 1 then account.name
When order.customertype = 2 then contact.fullname
End
2.isnull(account.name, contact.fullname)
Would one approach be more efficient? The benefit I see of option 1 is if the Application's validation fails and there are two values, or more customer types are added.
I'd appreciate your thoughts!
Thanks!
View all comments
Show parent comment
2
u/NotSeanPlott Feb 22 '17 edited Feb 22 '17
Sadly this is an "Enterprise" application. I don't think restructuring the table is in scope for my pay grade...
Also would it be efficient to do this? Both of the new tables would have the exact same columns, except "AccountID" or "ContactID". Also most queries are regarding orders from both CustomerTypes, which would mean a Union between the two queries each time?