0

I am trying to write an sql query in PHP My admin ,but facing an error could any one help please!

QUERY

ALTER TABLE `transactions` ADD `giftAmount` FLOAT NOT NULL DEFAULT '0' AFTER `recievingCurrency` ,
ADD `giftCurrency` VARCHAR NULL DEFAULT NULL AFTER `giftAmount`

ERROR

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL DEFAULT NULL AFTER giftAmount' at line 2

HELP

2
  • Is the MySQL manual really that hard to understand? Commented Jul 3, 2014 at 7:44
  • A nullable column by definition has a default value of NULL. The error message is quite clear and point to the exact location of the error. Remove DEFAULT NULL and try again Commented Jul 3, 2014 at 7:45

2 Answers 2

2

Your syntax is not correct. Try:

ALTER TABLE `transactions`
  ADD `giftAmount`   FLOAT   NOT NULL DEFAULT '0'  AFTER `recievingCurrency` ,
  ADD `giftCurrency` VARCHAR                       AFTER `giftAmount`

You don't need to explicitly say DEFAULT NULL - it already is NULL by default.

Sign up to request clarification or add additional context in comments.

Comments

1

You have to give size of varchar datatype like

ADD `giftCurrency` VARCHAR(100) DEFAULT NULL AFTER `giftAmount`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.