473,395 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Creating self referencing table from multiple tables

Hi,

I have three tables:

Countries:
ID
Country

States:
ID
State
CountriesID

Cities:
ID
City
StatesID

I want to roll these into a single self-referencing table using Access
or Sql Server:

Region:
ID
Name
ParentID

....where the top level (countries) would have a ParentID of null and
others would cascade from that.

Can anyone point me to a query to build this table?

Thanks, Paul.
Nov 13 '05 #1
2 3802
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You'd probably save yourself a lot of maintenance by just having a table
like this:

CREATE TABLE Regions (
region_id COUNTER NOT NULL UNIQUE,
country VARCHAR(25) NOT NULL ,
[state] VARCHAR(25) NOT NULL ,
city VARCHAR(30) NOT NULL ,
CONSTRAINT PK_Region PRIMARY KEY (country, [state], city)
)

A COUNTER is an AutoNumber data type in Access/JET.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQmUP3oechKqOuFEgEQIi0QCaAszdippbE3KG7yKwWkytFD lrND8An3A6
uxMRGLtlPEq2jZV0Gsqjlxc+
=HMoY
-----END PGP SIGNATURE-----

Paul Cook wrote:
Hi,

I have three tables:

Countries:
ID
Country

States:
ID
State
CountriesID

Cities:
ID
City
StatesID

I want to roll these into a single self-referencing table using Access
or Sql Server:

Region:
ID
Name
ParentID

...where the top level (countries) would have a ParentID of null and
others would cascade from that.

Can anyone point me to a query to build this table?

Thanks, Paul.

Nov 13 '05 #2
How are you going to link a city to a country if that country doesn't have
any states. The only countries that have official states that I know of is
the USA and Australia. There might be a few more but they are in the
minority.

Jeff
"Paul Cook" <pa******@hotmail.com> wrote in message
news:de**************************@posting.google.c om...
Hi,

I have three tables:

Countries:
ID
Country

States:
ID
State
CountriesID

Cities:
ID
City
StatesID

I want to roll these into a single self-referencing table using Access
or Sql Server:

Region:
ID
Name
ParentID

...where the top level (countries) would have a ParentID of null and
others would cascade from that.

Can anyone point me to a query to build this table?

Thanks, Paul.

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sreddy | last post by:
I am trying to write a sql query on self referencing table. Just to brief ..Database is related to a Hiring department of the Qwest company. I need to generate a Report used by in HR...
2
by: Kamlesh | last post by:
Hi, I am using SQL Server 7.0 TABLE1 ====== Fld1 Fld2 Fld3
11
by: randi_clausen | last post by:
Using SQL against a DB2 table the 'with' key word is used to dynamically create a temporary table with an SQL statement that is retained for the duration of that SQL statement. What is the...
6
by: Christopher Harrison | last post by:
Is there a way to store an indefinite number of keys in one field and self join them? Imagine, for example, you have a table of users with a "friends" column. Say user 1 is friends with users 9, 7,...
6
by: F-13 | last post by:
I'm working on a BOM in Access 200 from an example downloaded from from the web. The sample database contains three tables, Assemblies (the list of items needed to assemble any assembly),...
6
by: John E | last post by:
I have a question about how to make records in a table reference other records in the same table.... Suppose I'm building a small database to track some basic information on several companies....
1
by: jenson | last post by:
<?php /* * Created on Apr 13, 2007 * * To change the template for this generated file go to * Window - Preferences - PHPeclipse - PHP - Code Templates */ require_once 'init.php'; ...
3
by: Guv | last post by:
Hello, Is there a way either via a make table query or code to create multiple tables with the same format. eg if table 1 had ccy, ccy1 and ccy2 as fields I would like to create additional tables...
6
by: firefighter17103 | last post by:
Hi All, I am new to MS Access 07, & do not know any VB, on a new business adventure. I am running Office07 on Vista Home Premium. I am in the process of creating a database that in the end I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.