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.
Well first job is to add the column with an alter table statement.
As in something like
Then you need to poulate it, that would be with a bunch of update statements
Say with something like
or if say Crocodile was 679
Or if you prefer it a bit more readable
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
Might do the job
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.