![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
-- State -- City |

#2
| |||
| |||
|
|
Hi, I have the following tables: CREATE TABLE [tblGeography] ( [ZoneID] Int, [ZoneName] [char] (10), [StateID] Int, [StateName] [char] (35), [CityID] Int, [CityName] [char] (50) ) CREATE TABLE [tblCustomers] ( [CustCode] [varchar] (20) , [CustName] [varchar] (64), [CityID] Int ) The logic is as follows: Zone | |-- State | |-- City What I want to do is "flatten" my data. I am thinking about creating a view as follows: 1) Add the tables listed above 2) Link the CityID fields between the Two Tables 3) Add all fields from Customer table EXCEPT for the CITYID field 4) Add all Name fields (ZoneName, StateName, CityName) from Geography table Is my approach correct and will it yield the correct and desired results? The reason for asking is because I don't recall exactly what I did but while trying this out I got a much higher count(*) of customers than the actual number of customers... I must have done something wrong ![]() Anyway...I'll appreciate your help. -- Thanks. |
#3
| |||
| |||
|
|
|Learner |Why not just to have each table for the data? |CREATE TABLE Zones |( | ZoneId INT NOT NULL PRIMARY KEY, |ZoneName VARCHAR(100) NOT NULL |) |CREATE TABLE States |( | StateId INT NOT NULL PRIMARY KEY, |StateName VARCHAR(100) NOT NULL |) |........... | |CREATE TABLE Customer_Details |( | CustCode INT NOT NULL REFERNCES Customers (CustCode ), | ZoneId INT NOT NULL REFERNCES Zones(ZoneId ), |StateId INT NOT NULL REFERNCES States(StateId ),.......... |........ |CONSTRAINT uid_PK PRIMARY KEY (CustCode ,ZoneId .......) Modify it for your |needs |) | |"Learner" <wantnospam (AT) email (DOT) com> wrote in message |news:MPG.1b3fc7d9df6dba06989708 (AT) msnews (DOT) microsoft.com... |> Hi, | |> I have the following tables: | |> CREATE TABLE [tblGeography] ( |> [ZoneID] Int, |> [ZoneName] [char] (10), |> [StateID] Int, |> [StateName] [char] (35), |> [CityID] Int, |> [CityName] [char] (50) |> ) | | |> CREATE TABLE [tblCustomers] ( |> [CustCode] [varchar] (20) , |> [CustName] [varchar] (64), |> [CityID] Int |> ) | | |> The logic is as follows: | |> Zone |> | |> |-- State |> | |> |-- City | | |> What I want to do is "flatten" my data. I am thinking about creating a |> view as follows: | |> 1) Add the tables listed above |> 2) Link the CityID fields between the Two Tables |> 3) Add all fields from Customer table EXCEPT for the CITYID field |> 4) Add all Name fields (ZoneName, StateName, CityName) from Geography |> table | |> Is my approach correct and will it yield the correct and desired |> results? The reason for asking is because I don't recall exactly what I |> did but while trying this out I got a much higher count(*) of customers |> than the actual number of customers... I must have done something wrong |> ![]() | |> Anyway...I'll appreciate your help. | |> -- |> Thanks. | | | |
![]() |
| Thread Tools | |
| Display Modes | |
| |