【发布时间】:2016-08-04 18:10:36
【问题描述】:
我曾考虑过使用 distinct 但我不太确定如何将其作为单个查询来提高代码效率,有没有办法?我基本上是在尝试检查是否已经存在数据条目,我正在尝试使用 BookingTime 进行检查。谢谢:)
这是我的 SQL 查询:
string bookingInfo = "INSERT INTO Booking(BookingDate, BookingTime, CustomerID, EmployeeID, ServiceType, BookingLength) " +
"VALUES (@BookingDate, @BookingTime, @CustomerID, @EmployeeID, @ServiceType, @BookingLength) " +
"where not exists (SELECT 1 FROM Booking WHERE BookingTime = @BookingTime)";
我收到的错误:“附加信息:查询输入必须包含至少一个表或查询。”
【问题讨论】:
-
如果发现重复,你想做什么?您想什么都不做,还是想用当前插入尝试中的值更新找到的记录?
-
目前我在考虑是否有重复项,只需向用户显示一条消息,不要将重复项添加到数据库中。
-
但是 BookingTime 是表的主键还是唯一索引?
-
目前是日期/时间数据类型。