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
 General SQL Server Forums
 Database Design and Application Architecture
 Database Design Issue

Author  Topic 

Bubsalubsa
Starting Member

1 Post

Posted - 2010-03-23 : 15:05:45
I have inherited a database from Access (with a VB front End) that has some critical design floors it looks much like this. Its aim is to send out quotes and then arrange collections I have re-solved soime issues with a few tables but this one I am struggling with. I have used SQL 2008 Access tool to convert the database to SQL to start re-writing to improve the performance.

As you can see if the same company has a different branch a new entry is made in the Customer Table if someone new joins the same company at the same branch again a new entry is made.

I have tried to normalise the database structure further below this table contains about 3000 records and maybe 300 duplicates so can manually handle some of the problems.

CUSTOMERS TABLE



ID Company Name Address 1 Address2 County QA Q Contact Q Address1

1 Red Cars Roger Doger Red House Red St Essex 0 Null Null
2 Green Cabs Billy Bullhat Green House Old St London 1 John Boy 44 Egg Rd
5 Blue Carts Peter Perfect Mint House One St Dorset 0 Null Null
6 Blue Carts Ltd Joe Bloggs Mint House One St Dorset 1 Sol Perfect Hull House
8 Blue Carts 1 Peter Perfect ME7 House Long St Kent 0 Null Null
9 Blue Carts 2 Gorden Green SE1 Park Comb Rd London 0 Null Null

The biggest problem I have though is how would you automate the import so the data, merge's correctly into the new database tables. In my above example we have 4 Blue Cars in the company column I would need to merge this into one company but only 3 branches as the 4th Blue Car is there only because of a different conact name but it has a duplicate address. I would also need to import the conatacts into a contact table again removing duplicates.

Here is rough idea of my normalised tables that I am looking to import into.

Address
-------
AddressId Int PK
Address1 VARCHAR
Address2 VARCHAR
City VARCHAR

Contact
--------
ContactID INT PK
ContactName VARCHAR
AddressId Int

Company
--------
CompanyID INT PK
CompanyName VARCHAR


Branch
--------
BranchID INT PK
CompanyID INT FK
BranchName VARCHAR


Customer
--------
CustomerID INT PK
ContactID INT FK
BranchID INT FK
QA BIT
QContact VARCHAR
QAddress1 VARCHAR

Any help with the sql query or logic would be great. One idea I was thinking of was adding to the flat file two coloumn named companyname and branchname writing a sql query updating the companyname = company and branchname = town then manually update the duplicates (All the Blue carts would be called Blue Carts in the new field companyname) and see if it is easier to import like that.
   

- Advertisement -