Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5960031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:46:07+00:00 2026-05-22T18:46:07+00:00

In my database, many tables have the ‘State’ field, representing the state that, that

  • 0

In my database, many tables have the ‘State’ field, representing the state that, that particular entity falls in. I have been told that we should use Lookup tables for this kind of thing, but I am unsure of the exact mechanism. Can someone clarify these points?

  1. How is the integrity maintained? (i.e. how do I make sure that only the values from the state table go into the other tables?)

  2. Does the state name go into the other tables, or does the state id from the state table go into the other tables?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:46:07+00:00Added an answer on May 22, 2026 at 6:46 pm

    1 – Integrity is maintained using what is called a FOREIGN KEY constraint. A reasonable scenario might have you do these two tables:

    Table Name: STATE_CODE
    ID    DESCRIPTION
    =================
    1   Alabama
    2   Arkansas
    ...
    50  Wyoming
    
    Table Name: CUSTOMER
    =====================
    CUST_ID   CUST_NAME   CUST_STATE
    100       AAA Company          1  --they are in Alabama!
    200       ZZZ Company          50 --they are in Wyoming!
    

    This answers your question #2: The state codes, not the full names, go in the CUSTOMER table in this example.

    A typical script to impose this kind of structure on an existing layout would be like this:

    --first, create the lookup table
    CREATE TABLE STATE_CODE(
      ID INTEGER NOT NULL
     ,DESCRIPTION VARCHAR(100) NOT NULL
     ,PRIMARY KEY(ID)
    );
    
    --now add a reference to the lookup table inside your existing table
    --the REFERENCES part will **force** entries
    --to have a matching entry in STATE_CODE
    ALTER TABLE CUSTOMER ADD STATE_CODE_ID REFERENCES STATE_CODE(ID);
    

    And this answers your question #1: That “REFERENCES” command will create a Foreign Key constraint that will force all entries in CUSTOMER.STATE_CODE to have a corresponding entry in the STATE_CODE table. After setting this up, if someone were to try this:

    INSERT INTO CUSTOMER(CUST_ID,CUST_NAME,CUST_STATE)
    VALUES(9000,'Martians',74837483748);
    

    Then they would get an error message, and that faulty data would never get entered (unless, of course, you really did have a state with a code of 74837483748).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have database with many tables. In the first table, I have a field
I have an access database with many tables. I am looking for a field
I have the following tables in my database that have a many-to-many relationship, which
I have a MySQL database that contains many tables, some of them created dynamically
I have a database with many tables that get used, and many tables that
I have a database that has several tables. Many of the tables have fields
I have many tables in my database which are interrelated. I have a table
I have a very large Oracle database, with many many tables and millions of
I have a table within my database that has many records, some records share
I have a star schema type data base, with fact tables that have many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.