这是我在stackoverflow中的第一个问题,我不是英语母语人士。如果我问的不好,请忍受。
假设我有一个表,其中_id
是主键。
| _id | value1 | value2 |
|-----|--------|--------|
| 1 | apple | banana |
| 2 | orange | melon |
我希望:
INSERT INTO table_name (_id, value1, value2) VALUES (1, 'apple', 'banana')
,则不会发生任何事情,因为整个行都是相同的。 INSERT INTO table_name (_id, value1, value2) VALUES (2, 'apple', 'tomato')
,则会收到警告,因为至少存在不等于一列。mysql中是否有任何简洁的语句,以便我可以做吸吮工作?
答案 0 :(得分:0)
您似乎想在public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging(logging => { logging.ClearProviders(); }) // clearing all other logging providers
.UseSerilog(); // Using serilog
上使用唯一索引:
_id
然后,您将无法插入具有相同create unique index unq_table_id on table(_id);
的另一行。如果您还希望它们为唯一索引,则可以为_id
和value1
创建唯一索引。
该行为与您指定的行为不完全相同。如果尝试使用现有的value2
插入 any 行-不管其他列中的值如何-都会发生错误。您可以根据需要使用_id
或insert ignore
绕过错误。