Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

A confusing SQL statement

I have a table for posts that contains column for user_id for the user that created the post. Its is a Foreign Key linking to my user table. That user is no longer with us I am have to remove him, but currently doing do will remove all of his post. I need to 'transfer' ownership. I can't seem to think out this SQL statement.

Thus far I have. UPDATE TABLE post.user_id WHERE user_id = X SET user_id = Y

1 Answer

Hi John

If i have understood you correctly you want to change the ID of the post that this user has posted that is no longer with you ?? at the same time you want to keep his posts. What i don't get is why do you need to change user_id?? that would be unique and would not effect your application in anyway?? apologies If i have miss understood you.

Normally you'd be right, I'd just keep the user account id. However DOD policy dictates that I not only deactivate his account I must purge it from the system. As such removing him causes a foreign key constraint conflict. So I need to keep his post by transferring ownership to a new user.