sql server 2012 - New database or index key for each client? -
we building web application using asp.net , microsoft sql server 2012. each of our customer have ability add other customers below them.
our company --> our customers ---> customer's customers
is preferable create new database each of our customer or use seperate table , automatically apply key filter in gui?
from have described (briefly) not suggest having separate db each client. if each client getting own application/website, yes, may want have each client have own instance of db (as application, server, etc). in case, seems each client need interact 1 another. difficult if located in various databases. instead, creating normalized database schema uses recursive table customers. can create schema similar this:
tblourcompany
companyid(pk int)
companyname(varchar) ....
tblourcustomers
custid(pk int)
custname(varchar)
custparent(int)
tblcompany_customer
companyid(pk)
customerid(pk)
this quick mock table has company table (assuming have multiple companies or maybe might business units) , customers table. because may have multiple companies multiple customers, need have table unifies them both, company_customers table. crux of design, though, recursive design of customers table. each table have customerid, primary key, , parent id. parent id pk of customer found in customer table ( root parent have value of 0). example:
companyid | companyname | parentid ----------------------------------- 1 companya 0 2 companyb 0 3 companyc 1 4 companyd 1 5 companye 4
this example has 5 companies. 2 root companies (companya/b). companya has 2 children (c , d). companye has 1 child, companyd.
it important understand database normalization. if follow first inclination use different db each customer, spending great deal more money (db licenses cost money + server costs + space, etc) , causing unnecessary difficulty when comes getting data , working using sql , whatever applications may using it. heres quick intro normalization: http://databases.about.com/od/specificproducts/a/normalization.htm
if have other questions, let me know.
Comments
Post a Comment