Reputation: 6714
I am trying to add a prefix myprefix_
to MySQL table named post
. I got stuck in one place:
DELETE FROM `post` WHERE `post`.`post_id` = ?
I added myprefix_
here:
DELETE FROM `myprefix_post`
but what about second part?
WHERE `post`.`post_id` = ?
Should I change it to this?
WHERE `myprefix_post`.`post_id` = ?
W3Schools LINK gives an information that the syntax looks like this and I'm lost, because "post" is current table name:
FROM table_name WHERE condition;
Upvotes: 0
Views: 64
Reputation: 781210
You can assign an alias to the table name, then use the alias in the rest of the query.
DELETE FROM post AS p
WHERE p.post_id = ?
Then you can change the table name, but the rest of the query can continue to refer to it by the alias, so nothing else needs to change:
DELETE FROM myprefix_post AS p
WHERE p.post_id = ?
Otherwise, you'll need to change the table name prefix everywhere it appears:
DELETE FROM myprefix_post
WHERE myprefix_post.post_id = ?
Upvotes: 1