zoukankan      html  css  js  c++  java
  • 临时表用法其中两个

    临时表与永久表相似,但临时表存储在 tempdb 中,当不再使用时会自动删除。

    临时表有两种类型:本地和全局。它们在名称、可见性以及可用性上有区别。本地临时表的名称以单个数字符号 (#) 打头;它们仅对当前的用户连接是可见的;当用户从 SQL Server 实例断开连接时被删除。全局临时表的名称以两个数字符号 (##) 打头,创建后对任何用户都是可见的,当所有引用该表的用户从 SQL Server 断开连接时被删除。

    来自这里:传送门

    select*into #d from tachecontractid  --#d没有提前声明

      

    insertinto #temp
    select*from tachecontractid where id=@id --#temp提前创建的(跟创建正常表一样 create ...()...)
    selectidentity(int ,1,1) as id,*into #temp1 fromtachecontractid   --#temp1没有提前声明

      

    第一种很常用

    第二种次之

    第三种很有用ol~意思就是按照你原本的顺序加上一个字段 id(随便起) 让它自增长

    通过临时表可以给它加自增长的列 还可以用row_number()增加自增长

    select * from (select *,row_number() over (order by id) as 'id1' from #temp) as t where id1=1

    *******使用临时表的时候 ,要注意临时表的列的长度是多大,避免超出

    第一种:通过sql语法来改变

    select tmp1 as tmp2 into #tmp2 from tmp1
    --修改临时表列的长度
    alter table #tmp2 alter column tmp2 nvarchar(max)

    第二种:通过加长第一次插入的值的长度

    select tmp1 as tmp2,'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxx' as xx into #tmp2 from tmp1





  • 相关阅读:
    android gradle 多渠道打包
    Gradle Plugin User Guide 中文版
    最好的JAVA IDE IntelliJ IDEA使用简介(一)—之界面元素
    ANDROID 中UID与PID的作用与区别
    HTTP Header 详解
    HTTP协议详解
    Volatile总结
    Condition-线程通信更高效的方式
    JAVA基础知识点(转载的)
    CountDownLatch和CyclicBarrier的区别
  • 原文地址:https://www.cnblogs.com/0banana0/p/2159677.html
Copyright © 2011-2022 走看看