Skip to content

Instantly share code, notes, and snippets.

@tfentonz
Created August 18, 2015 00:04
Show Gist options
  • Save tfentonz/c832153b0b0947d52ac3 to your computer and use it in GitHub Desktop.
Save tfentonz/c832153b0b0947d52ac3 to your computer and use it in GitHub Desktop.
Test MySQL ALTER TABLE for timestamp column.
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