SQL自动增量按DateTime [英] SQL Auto-Increment by DateTime

查看:218
本文介绍了SQL自动增量按DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



所以说我有一张表

  mytable 
=========================== ====================
= Comment_ID = First_Name = Comment = DateTime =
=========== $ {
= 1 =鲍勃,========================== = FooBar = 11-01-14 11:00 =
= 2 = Jack = Blah = 11-01-14 12:29 =
= 3 = John = jonny = 12-01-14 07: 09 =
======================================== =========

有没有让日期自动递增? / p>

解决方案

在您的MySQL中运行此操作:

  ALTER TABLE`mytable` 
CHANGE COLUMN`DateTime`` DateTime` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP;

这将您的默认值设置为 CURRENT_TIMESTAMP


Is there a way in my sql to auto increment by the date and time?

so say I have a table

                         mytable
 =====================================================
 = Comment_ID = First_Name =  Comment  =  DateTime   =
 =====================================================
 =     1     =      Bob   =  FooBar = 11-01-14 11:00 =
 =     2     =     Jack   =  Blah   = 11-01-14 12:29 =
 =     3     =     John   =  jonny  = 12-01-14 07:09 =
 =====================================================

Is there away to make the date auto-increment?

解决方案

Run this in your MySQL:

ALTER TABLE `mytable` 
CHANGE COLUMN `DateTime` `DateTime` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ;

This sets your default value to CURRENT_TIMESTAMP.

这篇关于SQL自动增量按DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆