sql语句的区别
来源:10-1 课程总结
爱问问题的小菜鸡
2023-06-10 17:12:23
<insert id="insertSelective" parameterType="com.imooc.mall.model.pojo.Order">
insert into imooc_mall_order
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="orderNo != null">
order_no,
</if>
<if test="userId != null">
user_id,
</if>
<if test="totalPrice != null">
total_price,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="orderNo != null">
#{orderNo,jdbcType=VARCHAR},
</if>
<if test="userId != null">
userId,
</if>
<if test="totalPrice != null">
totalPrice
</if>
</trim>
</insert>与
<insert id="insert" parameterType="com.imooc.mall.model.pojo.Order">
insert into imooc_mall_order (id, order_no, user_id,
total_price)
values (#{id,jdbcType=INTEGER}, #{orderNo,jdbcType=VARCHAR}, #{userId,jdbcType=INTEGER},
#{totalPrice,jdbcType=INTEGER})
</insert>当其中的某个字段没有传,存到数据库中的值会有什么区别吗?
如果数据库中的某个字段是时间戳,设置了默认值为CURRENT_TIMESTAMP,比如说create_time这个字段没有传给sql语句,这两个代码有区别吗?
1回答
好帮手慕小蓝
2023-06-12
同学你好~
1.值会有区别的:第一条语句中的,如果某些字段没有传入数据,那么会采用默认值。但是第二条,要求所有字段都必须传入数据,所以必然不会采用默认值。
2.没有区别:因为两条sql中,都没有对create_time字段进行设置,那么最终都会采用默认值。
祝学习愉快~
相似问题