473,799 Members | 2,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3818
-----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:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQmUP3oechKq OuFEgEQIi0QCaAs zdippbE3KG7yKwW kytFDlrND8An3A6
uxMRGLtlPEq2jZV 0Gsqjlxc+
=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******@hotma il.com> wrote in message
news:de******** *************** ***@posting.goo gle.com...
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
11538
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 department to pay the employees who have referred the candidates for the jobs in their .. This report is used by the HR department to get the required
2
19244
by: Kamlesh | last post by:
Hi, I am using SQL Server 7.0 TABLE1 ====== Fld1 Fld2 Fld3
11
16299
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 equivalent to the SQL 'with' using TSQL? If there is not one, what is the TSQL solution to creating a temporary table that is associated with an SQL statement? Examples would be appreciated. Thank you!!
6
2644
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, 24 and 6; then would it be possible to store this array/list/whatever-you-want-to-call-it into user 1's friends cell and extract the join in a query, some how? An easy and obvious way, that is; I can think of string processing hacks ;) Thanks...
6
7646
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), Components (the list of items recognised by the Assemblies Table)and Output (a table used to display the BOM from a chosen assembly). It works fine but there are no forms. For a user to edit or create a BOM, should there be a form for each assembly of...
6
8631
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. In addition to the ID and other info, I want to track predecessor and succesor companies, if any. In other words, a given company may have come into being from the merger of two or more predecessors, may have been spun-off from a single...
1
3329
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'; $con=mysql_connect("localhost","root",""); $dbc=mysql_select_db(test,$con)or die("Database select error:" . mysql_error($con));
3
1290
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 with the same fields but with different names. I know you can create one table via a standard make table query - is there a way of creating multiple tables? Thanks in advance
6
8013
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 will be able to create quotes, bill out customers for security services, cctv products and installs,create purchase orders to my distributors being that I keep no inventory on hand, and track payments such as deposits on equipment. What I need help...
0
10495
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10269
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4148
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.