mysql自動管理資料的建立時間和更新時間

2021-09-24 21:27:03 字數 880 閱讀 3652

首先在建立表的時候

create table testmysqltime(

-> id int primary key auto_increment comment '主鍵id',

-> username varchar(10) not null comment '使用者名稱',

-> password varchar(10) not null comment '使用者密碼',

-> createtime timestamp not null default current_timestamp comment '建立時間',

-> updatetime timestamp not null default current_timestamp on update current_timestamp comment '更新時間') comment '測試時間表';

在插入資料的時候 :

insert into testmysqltime (username, password) values ("admin", "123456");

這樣我們在操作新增資料的時候 就不用考慮關於資料建立的時間的問題了。

在更新資料的時候

update testmysqltime set password="456789" where id=1;

這樣我們在操作更新資料的時候 就不用考慮關於資料建立的時間的問題了。

注意的是:同一資料多次更改 更改的資料是相同的  那 更新的時間是不變化的

例如:update testmysqltime set password="456789" where id=1;  執行多次  更新時間還是第一次執行的時候的更新時間,除非你更改資料  把password="4567890"進行更改  在執行 更新時間就是當前時間了

mysql自動建立分割槽

call insert partition 2018 07 07 2019 01 01 儲存過程 begin declare nowdate date declare endtmp date declare dt varchar 256 declare partitiontemp varchar 2...

MySQL建立和管理資料庫

使用t sql 語句建立資料庫 使用t sql 語句編輯資料庫 1 要求在本地磁碟d建立乙個學生 課程資料庫 名稱為student 只有乙個資料檔案和日誌檔案,檔名稱分別為stu和stu log,物理名稱為stu data.mdf 和stu log.ldf,初始大小都為3mb,增長方式分別為10 和...

Mysql查詢資料時,自動為結果編上序號

自己之前沒遇到過這種在查詢時給結果編號的情況,是同事打算跳槽,面試回來問到這種情況才想到去研究,以下以單錶查詢為例分析下 sql select i i 1 i,user id,user name fromdt user all orders,select i 0 as i where user na...