Reputation: 8405
Hey guys I was trying to alter my tables column to take
the current time stamp on creation, the error I'm getting
is #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 '( 'inspection_number' NOT NULL default CURRENT_TIMESTAMP )' at line 1
I was trying to use
ALTER TABLE `reports` (
`inspection_number` DATE NOT NULL default CURRENT_DATE
);
But I"m not seeing the error?
Upvotes: 0
Views: 86
Reputation:
Seems syntax is not correct. Use below :
if adding new column inspection_number
:
ALTER TABLE `reports` ADD COLUMN `inspection_number` timestamp NOT NULL default CURRENT_TIMESTAMP
if modifying existing inspection_number
column:
ALTER TABLE `reports` MODIFY COLUMN `inspection_number` timestamp NOT NULL default CURRENT_TIMESTAMP
Please specify datatype of column
Upvotes: 1
Reputation: 604
The syntax you have there is for when you create a table. When you modify a table and want to set a default value use:
ALTER TABLE table_name MODIFY col_name col_type NOT NULL DEFAULT CURRENT_TIMESTAMP;
Upvotes: 0
Reputation: 1380
ALTER TABLE `reports`
MODIFY `inspection_number` TIMESTAMP NOT NULL default CURRENT_TIMESTAMP ;
Upvotes: 0
Reputation: 62395
You're missing a MODIFY
ALTER TABLE `reports` (
MODIFY `inspection_number` NOT NULL default CURRENT_TIMESTAMP
);
Upvotes: 0