Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / September 2005

Tip: Looking for answers? Try searching our database.

sql trouble

Thread view: 
anonymous.coward.01@gmail.com - 27 Sep 2005 20:21 GMT
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.
Bill Karwin - 27 Sep 2005 20:42 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.