编程知识 cdmana.com

MySQL addition, deletion and modification

Add data

Native SQL

Insert the specified field
grammar :

insert into  The name of the table ( Field 1, Field 2, Field 3) values ( value 1, value 2, value 3);

Example :

INSERT INTO test(id, name, parent_id, deep, type, create_time, update_time) VALUES('12ab9807bda',' classification ','2222',2,3,'2022-08-07 12:45:12', '2021-09-08 02:12:56');

Insert full field
grammar :

insert into  The name of the table  values( value 1, value 2, value 3,..., All field values );

Example :

INSERT INTO test VALUES('ab129856abc40',' classification ','2222',2,3,'2022-08-07 12:45:12', '2021-09-08 02:12:56');

mybatis

mapper Interface :

    void insert(@Param("entity") Category category);

mapper layer SQL sentence :

    <insert id="insert">
        INSERT INTO category(id, name, parent_id, deep, type, create_time, update_time)
        VALUES(#{entity.id}, #{entity.name}, #{entity.parentId}, #{entity.deep}, #{entity.type}, #{entity.createTime}, #{entity.updateTime});
    </insert>

Update data

Native SQL

grammar :

 UPDATE  The name of the table 
 SET  Field name 1=  value 1,
  Field name 2=  value 2,
  Field name 3 =  value 3

Example :

 UPDATE category
 SET name = ' Three lives, three lives ',
 parent_id = '222222',
 level = 2
 WHERE id = '4'

mybatis

mapper sentence :

    void updateCategory(@Param("entity") Item item);

mapper layer SQL sentence :

        UPDATE item
        <trim prefix="SET" suffixOverrides=",">
            <if test="entity.catId != null and entity.catId != ''">
                cat_id = #{entity.catId},
            </if>
            <if test="entity.catName != null and entity.catName != ''">
                cat_name = #{entity.catName},
            </if>
            <if test="entity.updateId != null and entity.updateId != ''">
                update_id = #{entity.updateId},
            </if>
        </trim>
        WHERE id = #{entity.id}

版权声明
本文为[gugugutime]所创,转载请带上原文链接,感谢
https://cdmana.com/2022/134/202205141324554985.html

Scroll to Top