用户登录
用户注册

分享至

触发器TRIGGER 自增IDENTITY 聚集索引CLUSTERED

  • 作者: 洒家是只猫
  • 来源: 51数据库
  • 2021-09-03

在触发器的“触发”过程中,有两个临时表inserted和deleted发生了作用。这两个特殊的临时表inserted和deleted,仅仅在触发器运行时存在,它们在某一特定时间和某一特定表相关。

create table [dbo].[a] (
[id] int identity (1, 1) not null, //自增identity(m,n)从m开始每次加n
[created] datetime default (getdate()) not null,
[updated] datetime null,
primary key clustered ([id] asc)//clustered 是聚集索引插入时会花费时间  查询时省时
);

//举个例子,如果一个页面已经写满了数据,你要插入一行,如果是非聚集索引,

//sql会随便找个地方保存,把地址记录进索引,但是如果是聚集索引,

//会把数据插入到这个页面,而后面的数据同时会往后移动(用页面拆分的办法),

//看上去速度要慢,但是聚集索引在搜索时,速度会比非聚集索引快,因为他们是物理排序的

go
create trigger trigaupd
on a for update
as update a set updated = getdate() where id in (select id from inserted);

软件
前端设计
程序设计
Java相关