Created
August 18, 2015 00:04
-
-
Save tfentonz/c832153b0b0947d52ac3 to your computer and use it in GitHub Desktop.
Test MySQL ALTER TABLE for timestamp column.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop table if exists `cars`; | |
create table `cars` ( | |
`id` int not null auto_increment, | |
`make` varchar(255), | |
`model` varchar(255), | |
`created_at` timestamp default current_timestamp not null, | |
`updated_at` timestamp default current_timestamp on update current_timestamp not null, | |
primary key (`id`) | |
); | |
insert into `cars` (`make`, `model`) values ('Honda', 'Accord'); | |
select * from `cars`; | |
select `updated_at` from `cars`; | |
alter table `cars` | |
modify `created_at` timestamp(6) | |
default current_timestamp(6) not null; | |
alter table `cars` | |
modify `updated_at` timestamp(6) | |
default current_timestamp(6) on update current_timestamp(6) not null; | |
insert into `cars` (`make`, `model`) values ('Toyota', 'Aurion'); | |
select * from `cars`; | |
select `created_at`, microsecond(`created_at`) as 'microsecond' from `cars`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment