日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

SQL 语句规范

發布時間:2025/4/5 数据库 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SQL 语句规范 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為什么80%的碼農都做不了架構師?>>> ??

一、基本T-SQL 語句

程序中一般使用的基本sql語句

?

模式

Inset

Insert? into? 表名? (列名1,列名2,列名3,...) values?? (值1,值2,值3,...)

delete

Delete from where 列名1 = 值1 and 列名2 = 值2 and 列名3 = 值3...

update

Update 表名? set? 列名1 = 值1 ,列名2 = 值2 ,列名3 = 值3…? ?

Select

Select 列名1,列名2,列名3...? from 表名? where 列名1 = 值1 and 列名2 = 值2 and 列名3 = 值3...

示例:以mybatis為例。

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.apps.sys.mapper.ArticleMapper">

<sql id="tableName">

tb_Article

</sql>

<sql id="keyId">

id

</sql>

<sql id="Columns">

type_id,user_id,sitemodules_id,status,bigTile,smallTitle,content,source,author,publishTime

</sql>

<sql id="selectColumns">

<if test="id !=null">and id=#{id} </if>

<if test="typeId !=null">and type_id=#{typeId} </if>

<if test="userId !=null">and user_id=#{userId} </if>

<if test="sitemodulesId !=null">and sitemodules_id=#{sitemodulesId} </if>

<if test="bigTile !=null">and bigTile=#{bigTile} </if>

<if test="smallTitle !=null">and smallTitle=#{smallTitle} </if>

<if test="author !=null">and author=#{author} </if>

<if test="publishTime !=null">and publishTime=#{publishTime} </if>

<if test="source !=null">and source=#{source} </if>

<if test="content !=null">and content=#{content} </if>

</sql>

?

<sql id="updateColumns">

<if test="typeId !=null">, type_id=#{typeId} </if>

<if test="userId !=null">, user_id=#{userId} </if>

<if test="sitemodulesId !=null">, sitemodules_id=#{sitemodulesId} </if>

<if test="bigTile !=null">, bigTile=#{bigTile} </if>

<if test="smallTitle !=null">, smallTitle=#{smallTitle} </if>

<if test="author !=null">, author=#{author} </if>

<if test="publishTime !=null">, publishTime=#{publishTime} </if>

<if test="source !=null">, source=#{source} </if>

<if test="content !=null">, content=#{content} </if>

</sql>

?

<insert id="insertOne" parameterType="Article" useGeneratedKeys="true" keyProperty="id">

Insert

?<include refid="tableName"/> (<include refid="Columns"/>)

values (#{typeId},#{userId},#{sitemodulesId},#{bigTile},#{smallTitle},#{content},#{source},#{author},#{publishTime})

</insert>

?

<delete id="deleteOne" parameterType="int">

delete from

<include refid="tableName"/>

where id=#{id}

</delete>

?

<update id="updateByColumns" parameterType="Article">

Update

?<include refid="tableName"/>

?set id=#{id}

<include refid="updateColumns"/>

?where id=#{id}

</update>

?

<select id="selectOneById" parameterType="int" parameterType="Article">

select

<include refid="keyId" />,<include refid="Columns"/>

?from <include refid="tableName"/> where id=#{id}

</select>

?

<select id="listPageAll" resultMap="ArticleResultMap">

select * from <include refid="tableName"/>

</select>

?

<select id="listPageByColumns" parameterType="Article" resultMap="ArticleResultMap">

select

<include refid="keyId" />,<include refid="Columns"/>

?from

<include refid="tableName"/>

? where 1=1

<include refid="selectColumns"/>

</select>

?

<select id="selectByColumns" parameterType="Article" resultMap="ArticleResultMap">

select

<include refid="keyId" />,

<include refid="Columns"/>

?from

<include refid="tableName"/>

?where 1=1

<include refid="selectColumns"/>

</select>

</mapper>

?

二、查詢的方法

public Integer insertOne(Role role);

根據字段是否為空添加相應的字段

public Integer deleteOneById(String Id);

根據id刪除一條記錄

public Integer updateOne(Role role);

根據字段是否為空更新相應的字段

public Role selectOneById(String id);

根據id查詢一條記錄

public List<Role> selectListByObj(Role role);

根據對象單表查詢出多條記錄

public List<Role> selectListrefLJByObj(Role role);

根據對象左鏈接查詢出多條記錄

public List<Role> selectListrefRJByObj(Role role);

根據對象右鏈接查詢出多條記錄

public List<Role> selectListrefFJByObj(Role role);

根據對象全鏈接查詢出多條記錄

public List<Role> listPageByObj(Role role);

根據對象單表分頁查詢出多條記錄

public List<Role> listPageRefLJByObj(Role role);

根據對象左鏈接分頁查詢出多條記錄

public List<Role> listPageRefRJByObj(Role role);

根據對象右鏈接分頁查詢出多條記錄

public List<Role> listPageRefFJByObj(Role role);

根據對象全鏈接分頁查詢出多條記錄

轉載于:https://my.oschina.net/jimiao/blog/746215

總結

以上是生活随笔為你收集整理的SQL 语句规范的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。