zoukankan      html  css  js  c++  java
  • Sql相关

    临时表是利用了硬盘(tempdb数据库) ,表名变量是占用内存,因此小数据量当然是内存中的表变量更快。当大数据量时,就不能用表变量了,太耗内存了。大数据量时适合用临时表。

    临时表:create table #tb(id nvarchar(10))

    或者 SELECT id   INTO #tb   FROM mytable 

    表变量 
    declare @tb table( id nvarchar(10))
    select * from @tb

    或者 with cet as (select * from tableName)

    表值函数

    Create  FUNCTION f_Name

    (
     @ID varchar(50)='0'
    )

    RETURNS @tb table(id varchar(50)

    标量函数

    Create FUNCTION f_Name
    (
      @ID varchar(50)
     
    )
    RETURNS float
    AS
    BEGIN

    END

     更新触发器

    CREATE TRIGGER [dbo].[TR_Update_XXX]
       ON  [dbo].[XXX]
       for update
    AS
    BEGIN 
     SET NOCOUNT ON; 
     if update(ColumnName)
      begin
       declare @before varchar(50)
       declare @aftert varchar(50)

       select @before=ColumnName from deleted
       select @aftert=ColumnName from inserted
       
       if(@before<>@aftert)

    删除触发器

    ALTER TRIGGER [dbo].[TR_DELETE_XXX]
       ON  [dbo].[XXX]
       AFTER  DELETE
    AS
    BEGIN
     -- SET NOCOUNT ON added to prevent extra result sets from
     -- interfering with SELECT statements.
     SET NOCOUNT ON;
     DECLARE @typeName nvarchar(50);
     select @typeName= XXXfrom deleted

    游标:

    declare c cursor for select * from XXX

    open c
       fetch next from c into @v1,@v2
       
       while  @@fetch_status=0
       begin
          
        fetch next from c into   @v1,@v2
       end
       close c   
        DEALLOCATE c  

  • 相关阅读:
    图片的通道数和卷积核的深度
    神经网络中使用Batch Normalization 解决梯度问题
    python3没有urllib2 出现报错:语法错误
    pip安装时ReadTimeoutError解决办法
    我的学习
    动态(不定长)数组初始化
    关于c中的一些新函数
    排序算法
    vc6.0批量加注释
    endnote的安装和使用必备的几个步骤(简单有效整理版)
  • 原文地址:https://www.cnblogs.com/fuhui/p/1942442.html
Copyright © 2011-2022 走看看