December 22, 2007 at 5:40 pm
Hey Guys,
I have 10 tables of Individuals info (id, street address, city, state, ...) broken down by starting digit of Zipcode... 0..9. I need to break these 10 tables into 50 tables 1 for each state ... Each state will have its own table... What is the best way to do this?
Thanks a lot for your time and assistance.
December 22, 2007 at 7:22 pm
That's an ugly design. Just curious, why would you want that anyway? One table with a suitable index would (in just about all cases) be better, and certainly easier to use (depending on your client tools I suppose).
Anyway, you'll need lots of ugly dynamic SQL. If you just need to do this once, or to generate the code once, then you could do something like
create view vMergedPostcodeTables --this is for convenience
as
select * from tbl_postcode_1
UNION ALL
select * from tbl_postcode_2
UNION ALL
select * from tbl_postcode_3
UNION ALL
etc, etc
Then do
select 'select * into [tbl_state_' + state + '] from vMergedPostcodeTables where state = ' + quoteName(state, '''')
from (select distinct state from vMergedPostcodeTables)
This will generate all of your select * into [state_table] from Postcodes for each state. Copy the output and paste into a new query window.
December 22, 2007 at 7:47 pm
I need to break these 10 tables into 50 tables 1 for each state ... Each state will have its own table... What is the best way to do this?
Please explain why you need to do this...
--Jeff Moden
Change is inevitable... Change for the better is not.
December 22, 2007 at 7:54 pm
Basically I have 10 tables of Individuals Info broken down by First Digit of Zip... like all the zip starting from 1 has table called tble1 and so on... I need to use those 10 tables and break them into 50 tables by state... all the tables have state column too... Total number of records from all tables is around 40 million. Thanks for the help... Do you think I am better off creating a huge table with all 40 million records and then breaking them by using where clause?
December 22, 2007 at 8:00 pm
Yes, and place an index on the State column. There's jus no logical reason that i can think of to seperate the data when it's all related. I can see your successive queries being rather difficult to manage. I mean, you'd have to determine which table to query based on which state and this just doesn't make sense. at least to me.. 😀
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgDecember 22, 2007 at 8:02 pm
Thanks for the help... actually those 50 tables have to be further matched against a huge table to append other info based on addresses.... I did not want to run that update on this huge table.
December 22, 2007 at 8:08 pm
Well if you restrict your updates by state and have the state column indexed, i believe the updates will take just as long as if you had them in separate tables.
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgDecember 22, 2007 at 8:10 pm
Thanks guys
December 22, 2007 at 9:03 pm
Jeff Moden (12/22/2007)
I need to break these 10 tables into 50 tables 1 for each state ... Each state will have its own table... What is the best way to do this?
Please explain why you need to do this...
I have one table now with index on State column; however, when I run the above script I get syntax error near ')'... Any help . thanks!
December 23, 2007 at 12:07 am
Which "above script"... don't waste time, be specific, please.
You also said you wanted to update the table with address info... heh... what if a person has 2 addresses?
--Jeff Moden
Change is inevitable... Change for the better is not.
January 3, 2008 at 8:19 am
Could you post the file layout of the table in question? You may need to normalize it instead of breaking it into separate tables based upon artificial criteria.
Steve
January 4, 2008 at 4:54 pm
Thanks a lot guys ... with all yours suggestion, I was able to complete this. Happy new year.
January 4, 2008 at 7:03 pm
Please share what you did...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply