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

  • SEARCH
  • Home
  • 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 8004775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:00:57+00:00 2026-06-04T17:00:57+00:00

I have a table that looks like this: CODE ANIMAL 123 Alligator 1254 Cardinal

  • 0

I have a table that looks like this:

CODE ANIMAL

123  "Alligator"
1254 "Cardinal"
5675 "Golden Retreiver"

And I have another table that looks like this:

CODE  TYPE
12367 Reptile
12    Bird
56    Dog 

I want to add the column Type to the first table based on the code. I am not sure how to proceed.

  • 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-06-04T17:00:58+00:00Added an answer on June 4, 2026 at 5:00 pm

    Well first job is to add the column with an alter table statement.

    As in something like

    Alter Table Animals Add AnimalTypeCode int null
    

    Then you need to poulate it, that would be with a bunch of update statements

    Say with something like

    Update Animals 
    Set AnimalTypeCode = 12367
    Where Code = 123
    

    or if say Crocodile was 679

    Update Animals 
    Set AnimalTypeCode = 12367
    Where Code in (123,679)
    

    Or if you prefer it a bit more readable

    Update Animals 
    Set AnimalTypeCode = 12367
    Where Animal in ('Alligator','Crocodile')
    

    Keep bashing away until they all got one, perhaps adding some new types as required, thenn you can add a foreign key.

    No easy way to do this unless you’ve stashed away a table somewhere linking animal to animal type

    Editted to add. Given AnimalCode = AnimalTypeCode * 100 + ? then

    Update Animals
    Set AnimalTypeCode = Cast(AnimalCode / 100 as Int)
    

    Might do the job

    Select * 
    From Animals
    outer join AnimalTypes On Animals.AnimalTypeCode = AnimalTypes.Code
    Where AnimalTypes.Code is null
    

    Will give you all those where animaltypecode is not pointing to an existing animal type.

    The one you’ll have to be wary of is 1269, Elephant, Bird(12). If you have anything like that you’ll have to fix them individually.

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

Sidebar

Related Questions

I have a table that looks something like this. EDIT - I re-extracted code.
I have a table code_prices that looks something like this: CODE | DATE |
I have a table structure that looks like this: Columns: Account Number Service Code
I have a table of data, that looks something like this: ID CODE 1
I have a table that looks like this: DECLARE @myTable TABLE (country varchar(max), code
I have a BUSINESS table that looks like this: BUSINESS_ID | BRN | CODE
I have a table that looks like this: nid vid tid 1 2 3
I have a table that looks like this: <table> <thead> <!-- random table headings
I have a table that looks like this: |StreetName NR| NR | |Teststreet 34|
I have a table that looks like this: id count 1 100 2 50

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.