--事务
use MySchool--开启事务
begin transaction--声明局部变量
declare @errorSum intset @errorSum=0
update Bank set CusterMoney=CusterMoney-1000 where CusterName='李四'set @errorSum=@errorSum+@@ERROR --累计是否有误update Bank set CusterMoney=CusterMoney+1000 where CusterName='张三'set @errorSum=@errorSum+@@ERROR --累计是否有误if(@errorSum=0) begin
--提交事务 commit transaction endelse begin
--回滚事务 rollback transaction end
--视图
--判断是否有视图,若有删除
if exists (select *from sysobjects where name='vw_Student_Result')drop view vw_Student_Resultgo--创建学生和成绩视图create view vw_Student_resultasselect StuName 姓名,Grade 成绩 from Student,Result where Student.StuNo=Result.StuNogo--查看视图结果select *from vw_Student_result
--索引
语法:
create [unique] [clustered|nonclustered] index Index_name
on table_name (column_name[,column_name]....)
[with fillfactor=X]
其中clustered为聚集索引,nonclustered为非聚集索引
unique指定唯一索引
fillfactor表示填充因子,指定1~100的值,该值指示索引页填满的空间所占的百分比
例如:
--创建学生表的学生姓名的非聚集索引
create nonclustered index IX_Student_StuName
on Student(StuName)
with fillfactor =30
go
--索引的应用
select *from Student
with (index= IX_Student_StuName)where StuName like '张%'