kuhi
kuhi

Reputation: 653

How to add an option column in MySQL (Xampp 8.0.0)

I want to modify the table users adding the column crypto

Trying to execute this query but I'm getting an error:

ALTER TABLE `users` ADD COLUMN `crypto` VARCHAR(255) NULL '{"bitcoin": 0, "ethereum": 0, "bitcoin-cash": 0, "bitcoin-sv": 0, "litecoin": 0, "binance-coin": 0, "monero": 0, "dash": 0, "zcash": 0, "maker": 0}';

This is the error: You have an error in your SQL syntax

enter image description here

If I try to create the column manually and setting the default values I get the same error.

Upvotes: 0

Views: 611

Answers (2)

endo64
endo64

Reputation: 2307

You just forget DEFAULT in your query:

ALTER TABLE `users` ADD COLUMN `crypto` VARCHAR(255) NULL DEFAULT '{"bitcoin": 0, "ethereum": 0, "bitcoin-cash": 0, "bitcoin-sv": 0, "litecoin": 0, "binance-coin": 0, "monero": 0, "dash": 0, "zcash": 0, "maker": 0}';

Upvotes: 0

Bill Karwin
Bill Karwin

Reputation: 562368

Declare a column DEFAULT value with the DEFAULT keyword.

ALTER TABLE `users` ADD COLUMN `crypto` VARCHAR(255) NULL DEFAULT '{"bitcoin": 0, "ethereum": 0, "bitcoin-cash": 0, "bitcoin-sv": 0, "litecoin": 0, "binance-coin": 0, "monero": 0, "dash": 0, "zcash": 0, "maker": 0}';

Upvotes: 1

Related Questions