Hi all....
I have this situation where i need to move data in an MS ACCESS
database from one table to the other using an sql script, and i am
having trouble dong that.
The existing database has the following:
table: SHAPE
SHAPE_ID primary key (counter)
SHAPE_NAME text
SHAPE_COLOR text
...and some other columns
table: ELEMENT
ELEMENT_ID primary key (counter)
ELEMENT_SHAPE_ID long, foreign key
ELEMENT_TYPE long
...and some other columns
the relation is one shape to many elements (SHAPE_ID to
ELEMENT_SHAPE_ID)
Now i want to move the COLOR from the SHAPE table to the ELEMENT table,
but i want to make the color into a new table...and add more attributes
to it...So i created a new table called ATTRIBUTE which will host the
color and other attributes as follows:
table: ATTRIBUTE
ATTRIBUTE_ID primary key (counter)
ATTRIBUTE_COLOR text
ATTRIBUTE_DENSITY double
....and some more columns...
and i made it related to the element table by a one-to-many relation,
so the element table becomes like this:
table: ELEMENT
ELEMENT_ID
ELEMENT_ATTRIBUTE_ID foreign key
Now the trouble begins. I want to move the existing data to the new
schema. is there a way to move the color of the shapes to the attribute
table (by creating a new attribute for every color) and then
associating this new attribute to every element of that shape?
I want to be able to do that by running SQL statements only.
I hope someone will be able to give me some help.
thanks
anonC.
> is there a way to move the color of the shapes to the attribute
> table (by creating a new attribute for every color) and then
> associating this new attribute to every element of that shape?
Based on what I've read, MS SQL Server and JET (MS Access) SQL languages
each have their own syntax to support a ulti-table UPDATE statements,
though they each have different syntax to achieve this. And it's not
standard SQL, for what it's worth.
MS SQL Server example:
UPDATE table1
SET field1 = t2.field2
FROM table2 t2, table1 t1
WHERE t2.pk = t1.fk
JET (MS Access) example:
UPDATE table1 t1
INNER JOIN table2 t2 ON t1.fk = t2.pk
SET t1.field1 = t2.field2
See also:
http://groups.google.com/group/microsoft.public.access/browse_thread/thread/b0c7
64770735b116
Regards,
Bill K.
anonymous.coward.01@gmail.com - 27 Sep 2005 21:12 GMT
Bill:
Thanks for your prompt response.
I am a little confuse as to what table1, table2, t1 and t2 are.
would you be kind enought to write the same thing again using my table
names, which will make it easier for me to understand.
i appreciate your help in advance.
thanks
hilz
Bill Karwin - 28 Sep 2005 00:06 GMT
> I am a little confuse as to what table1, table2, t1 and t2 are.
> would you be kind enought to write the same thing again using my table
> names, which will make it easier for me to understand.
If I understand your problem correctly, it may be something like this:
UPDATE SHAPE S
INNER JOIN ATTRIBUTE A ON S.SHAPE_ID = A.ATTRIBUTE_ID
SET A.ATTRIBUTE_COLOR = S.SHAPE_COLOR;
But I may not have the correct understanding. I recommend you refer to
MS Access documentation and make sure you understand how to use the
multi-table update syntax; never take someone's untested syntax on
Usenet and run it verbatim without understanding what it's going to do!
Regards,
Bill K.