有关SQL的一些小干货

59 阅读1分钟

一、SQL分页的语法

`select * from exam_question

order by 排序字段

offset 页码数*一页多少行数据 rows fetch next 一页多少行数据 rows only`

二、触发器的一些简单应用

1.什么是触发器

简单理解一下,通过一些操作事件(增删改)来触发特定程序的执行

2.触发器的种类

1、after触发器(之后触发)

  2、instead of 触发器 (之前触发)

        a、 insert触发器

        b、 update触发器

        c、 delete触发器

触发器实例

以新增触发器为实例

image.png

当我们在进行添加学生的时候 如果学生处于正常状态则添加成,否则事物回滚.

三、存储过程的应用

1.修改存储过程

alter proc proc_get_student as select * from student;

2.创建存储过程格式

if (exists (select * from sys.objects where name = 'proc_get_student')) drop proc proc_get_student go

create proc proc_get_student

as

//填写执行的语句

select * from student;

//调用、执行存储过程

exec proc_get_student;