数据库
首页 > 数据库> > mysql建表时添加时间默认值只存储时分秒且自动存储

mysql建表时添加时间默认值只存储时分秒且自动存储

作者:互联网

mysql建表时添加时间默认值只存储时分秒且自动存储

	CREATE TABLE IF NOT EXISTS THI(
	THIId INT UNSIGNED AUTO_INCREMENT,
	t1 INT UNSIGNED NOT NULL,
	h1 INT UNSIGNED NOT NULL,
	i1 INT UNSIGNED NOT NULL,
	dataTime TIME NOT NULL,/*只存储时分秒*/
	PRIMARY KEY (THIId)
)

1.普通插入

INSERT INTO THI(t1,h1,i1,dataTime) VALUES(23,25,23,CURTIME())

2.防重插入

TIPS:即插入的数据不重复

INSERT INTO THI(t1,h1,i1,dataTime) 
SELECT 11,22,33,CURTIME()
FROM DUAL
WHERE NOT EXISTS
(
	SELECT t1,h1,i1
	FROM THI
	WHERE t1=11 AND h1=22 AND i1=33
);

标签:存储,NULL,建表时,i1,h1,UNSIGNED,t1,THI,默认值
来源: https://blog.csdn.net/qq135595696/article/details/120629439