SQL Server中临时表是在什么schema下的(转载)
Specifying schema for temporary tables
问:
I'm used to seeing temporary tables created with just the hash/number symbol, like this:
CREATE TABLE #Test
(
[Id] INT
)
However, I've recently come across stored procedure code that specifies the schema name when creating temporary tables, for example:
CREATE TABLE [dbo].[#Test]
(
[Id] INT
)
Is there any reason why you would want to do this? If you're only specifying the user's default schema, does it make any difference? Does this refer to the [dbo] schema in the local database or the tempdb database?
答:
It won't make any difference if you are specifying the users default schema, but if the users default schema changes then it will try to keep the temporary table in the dbo schema.
Temp tables are created in tempdb so it means you'd need to maintain the schema in tempdb, and offers no benefit.
跟帖:
If you create a schema on tempdb, and map a user to tempdb with that default schema, running CREATE TABLE #test (v INT) will create the table as "dbo.#test". Trying to create a temp table under a schema other than dbo will ignore the schema you speciy and create it in the dbo schema regardless. So CREATE TABLE dummy.#test (v INT) will also create "dbo.#test". --Jim
从上面最后Jim的跟帖中我们可以得知,临时表的schema默认都是位于tempdb数据库下的dbo,如果我们尝试给临时表声明非dbo的schema,例如:CREATE TABLE dummy.#test (v INT),SQL Server会忽略在临时表#test前声明的schema名dummy,创建的还是"dbo.#test",因此给临时表主动声明schema是没有意义的,所有的临时表都会创建在dbo这个系统schema下。
SQL Server中临时表是在什么schema下的(转载)的更多相关文章
- sql Server中临时表与数据表的区别
sql server 中临时表与数据表的区别 1.如何判断临时表和数据表已生成 --如何判断临时表是否已创建--- if exists(select * from tempdb..sysobjects ...
- 理解SQL Server中索引的概念,原理以及其他(转载)
简介 在SQL Server中,索引是一种增强式的存在,这意味着,即使没有索引,SQL Server仍然可以实现应有的功能.但索引可以在大多数情况下大大提升查询性能,在OLAP中尤其明显.要完全理解索 ...
- [转]SQL Server中临时表与表变量的区别
[转]http://blog.csdn.net/skyremember/archive/2009/03/05/3960687.aspx 我们在数据库中使用表的时候,经常会遇到两种使用表的方法,分别就是 ...
- SQL Server中临时表与表变量的区别
我们在数据库中使用表的时候,经常会遇到两种使用表的方法,分别就是使用临时表及表变量.在实际使用的时候,我们如何灵活的在存储过程中运用它们,虽然它们实现的功能基本上是一样的,可如何在一个存储过程中有时候 ...
- 谈一谈SQL Server中的执行计划缓存(下)
简介 在上篇文章中我们谈到了查询优化器和执行计划缓存的关系,以及其二者之间的冲突.本篇文章中,我们会主要阐述执行计划缓存常见的问题以及一些解决办法. 将执行缓存考虑在内时的流程 上篇文章中提到了查询优 ...
- SQL Server中的高可用性(3)----复制 (转载)
在本系列文章的前两篇对高可用性的意义和单实例下的高可用性做了阐述.但是当随着数据量的增长,以及对RTO和RPO要求的严格,单实例已经无法满足HA/DR方面的要求,因此需要做多实例的高可用性.本文着重对 ...
- SQL Server中INSERT EXEC语句不能嵌套使用(转载)
问: I have three stored procedures Sp1, Sp2 and Sp3.The first one (Sp1) will execute the second one ( ...
- c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程
c#Winform程序调用app.config文件配置数据库连接字符串 你新建winform项目的时候,会有一个app.config的配置文件,写在里面的<connectionStrings n ...
- SQL Server中的DATEPART函数的使用
下面文章来自:http://blog.csdn.net/hello_world_wusu/article/details/4632049 定义和用法 DATEPART() 函数用于返回日期/时间的单独 ...
随机推荐
- 《linux就该这么学》课堂笔记08 用户权限、特殊权限、隐藏权限、su、sudo
1.文件的读.写.执行权限可以简写为 r w x,亦可分别用数字4.2.1来表示 2.文件的特殊权限 2.1.SUID是一种对二进制程序进行设置的特殊权限,可以让二进制程序的执行者临时拥有属主的权限( ...
- 【HTTP】HTTP协议的请求与响应
创建时间:6.14 http协议 的位置 1.HTTP是什么 超文本传输协议(HyperText Transfer Protocol) 2.Http协议的组成 Http协议由Http请求和Http响应 ...
- AjAX 异步通信
<!DOCTYPE html> <html lang="en"> <head> <title>xmlhttprequest ajax ...
- css ie bug 双边距
- volatile 关键字 和 i++ 原子性
package com.mozq.multithread; /** * 深入理解Java虚拟机 volatile 关键字 和 i++ 原子性. */ public class VolatileTest ...
- JPA 基础
JPA 基础 数据库驱动 ==> JDBC 规范 ==> ORM 框架 ==> JPA 规范 ==> spring-data-jpa ORM 思想 JPA 的使用步骤 jpa ...
- Java Scanner语法
1.导入: import java.util.Scanner; 2.创建对象 Scanner scan = new Scanner(System.in);//一般变量名为scan或者in 最后关闭,s ...
- ES6异步操作Promise
什么是Promise Promise是异步编程的一种解决方案,说白了就是一个构造函数,带有all,reject,resolve这几个方法,圆形上有then,catch等方法 Promise的特点 对象 ...
- ESA2GJK1DH1K升级篇: STM32远程乒乓升级,基于GPRS模块AT指令TCP透传方式,定时访问升级(含有数据校验)
实现功能概要 单片机定时使用http访问云端的程序版本,如果版本不一致, 然后通过http下载最新的升级文件,实现远程升级STM32程序. 兼容Air202 ,SIM800 测试准备工作(默认访问我的 ...
- 基环树DP
基环树DP Page1:问题 啥是基环树?就是在一棵树上增加一条边. Page2:基环树的几种情况 无向 有向:基环外向树,基环内向树. Page3:处理问题的基本方式 1.断环成树 2.分别处理树和 ...