无则插入有则更新(PostgreSQL,MySQL,Oracle、SqlServer)

无则插入有则更新

PostgreSQL

无则插入有则更新

conflict(带有唯一性约束的字段),根据此字段判断是更新还是插入

INSERT INTO student(id,name,sex)
VALUES
	('1', '小明', '男') ON conflict (id) DO
UPDATE 
	SET id= '1',
	name= '小明',
	sex= '男';

无则插入有则不做操作

INSERT INTO student(id,name,sex)
VALUES
	('1', '小明', '男') ON conflict (id) DO nothing;

MySQL,Oracle、SqlServer

mysqlhttps://www.cnblogs.com/luoxiao1104/p/17027999.html
[MySQL,Oracle,SqlServer]:https://blog.csdn.net/weidu01/article/details/111939654

猜你喜欢

转载自blog.csdn.net/weixin_42949219/article/details/132280439
今日推荐