当前位置:Gxlcms > 数据库问题 > [SQL] SQL SERVER基础语法

[SQL] SQL SERVER基础语法

时间:2021-07-01 10:21:17 帮助过:18人阅读

        set  @param2 =@param1 * @param1 

  参数默认值:存储过程只有最后一个参数可以有默认值.

 

19.索引

  [聚焦索引]:

  [非聚焦索引]:

  create index indexName on tableName(fieldName)

 

20.触发器

  对某个表的进行增删改操作时,自动执行一个操作.有2种方式执行,1是触发源操作前替换执行 2是触发源操作后执行

  临时表:inserted deleted

  2种方式:after | instead of

  3种触发源:insert update delete

  创建:

    create trigger triggerName

      after insert

      as  begin

      insert into T  select * from inserted

      end

  建议:影响效率 谨慎使用

 

 

21.游标

  逐行的操作数据

  对每条数据执行指定的

  使用:(让T表中每个人的年龄增1)

    declare c1 cursor for

    select id,age from T

    declare @id int

    declare @age int

    open c1

    fetch c1 into @id,@age

    while(@@FETCH_STATU = 0)

    begin

      set @age= 1 + @age

      update T set age = @age where id = @id

      fetch c1 into @id,@age

    end  

    close c1

    deallocate c1

 


[SQL] SQL SERVER基础语法

标签:@age

人气教程排行