Nikki Howard
Nikki Howard

Reputation: 1

How to change column name with "count" in the name in Mysql?

ALTER TABLE customer_rewards 
    ALTER COLUMN count(rental_id) total_rentals
    bigint(21);

I'm trying to change name of the column: count(rental_id) to total_rentals MySql recognizes count as a function instead of a column name. I can't go in and change the name where you create the table, I can only use DDL to modify existing columns. I've tried using quotes (both single and double) and it still isn't working. How can I get around this?

Upvotes: 0

Views: 672

Answers (1)

GMB
GMB

Reputation: 222592

I'm afraid to ask how that table ended up with such a column name... Anyway: this identifier contains parentheses, so it needs to be quoted: for this you need to use backticks in MySQL:

ALTER TABLE customer_rewards ALTER COLUMN `count(rental_id)` total_rentals bigint(21);

Upvotes: 3

Related Questions