What is the difference between SET and SELECT when assigning values to variables, in T-SQL?
http://vyaskn.tripod.com/differences_between_set_and_select.htm
https://stackoverflow.com/questions/3945361/set-versus-select-when-assigning-variables
- SET is the ANSI standard for variable assignment, SELECT is not.
- SET can only assign one variable at a time, SELECT can make multiple assignments at once.
- If assigning from a query, SET can only assign a scalar value. If the query returns multiple values/rows then SET will raise an error. SELECT will assign one of the values to the variable and hide the fact that multiple values were returned (so you'd likely never know why something was going wrong elsewhere - have fun troubleshooting that one)
- When assigning from a query if there is no value returned then SET will assign NULL, where SELECT will not make the assignment at all (so the variable will not be changed from its previous value)
- As far as speed differences - there are no direct differences between SET and SELECT. However SELECT's ability to make multiple assignments in one shot does give it a slight speed advantage over SET.
http://www.sql-server-helper.com/tips/set-vs-select-assigning-variables.aspx
| SET | SELECT |
| ANSI standard for variable assignment. | Non-ANSI standard when assigning variables. |
Can only assign one variable at a time.
SET @Index = 1 |
Can assign values to more than one variable at a time.
SELECT @Index = 1, @LoopCount = 10, |
When assigning from a query and the query returns no result, SET will assign a NULL value to the variable.
DECLARE @CustomerID NCHAR(5) |
When assigning from a query and the query returns no result, SELECT will not make the assignment and therefore not change the value of the variable.
DECLARE @CustomerID NCHAR(5) |
When assigning from a query that returns more than one value, SET will fail with an error.
SET = (SELECT [CustomerID] |
When assigning from a query that returns more than one value, SELECT will assign the last value returned by the query and hide the fact that the query returned more than one row.
SELECT @CustomerID = [CustomerID] |
What is the difference between SET and SELECT when assigning values to variables, in T-SQL?的更多相关文章
- Laravel - Union + Paginate at the same time? and another problem----1222 The used SELECT statements have a different number of columns (SQL: (select count(*) as aggregate from
### 这是这几天,碰到的一个比较头疼的问题 使用union all联合查询,同时laravel 生成分页,但发生报错? QueryException : SQLSTATE The used from ...
- 【转】The difference between categorical(Nominal ), ordinal and interval variables
What is the difference between categorical, ordinal and interval variables? In talking about variabl ...
- using the library to generate a dynamic SELECT or DELETE statement mysqlbaits xml配置文件 与 sql构造器 对比
https://github.com/mybatis/mybatis-dynamic-sql MyBatis Dynamic SQL What Is This? This library is ...
- SELECT 1,2,3...的含义及其在SQL注入中的用法
首先,select 之后可以接一串数字:1,2,3-只是一个例子,这串数字并不一定要按从小到大排列,也不一定从1开始,这串数字的值和顺序是任意的,甚至可以是重复的,如:11,465,7461,35 或 ...
- select count(1) from table where ..这句sql语句的作用
作用是计算一共有多少符合条件的行.1并不是表示第一个字段,而是表示一个固定值,count(1)和count(2)效果是一样的 count(*),执行时会把星号翻译成字段的具体名字,效果也是一样的,不过 ...
- select rows by values in a column from Dataframe
df.loc[df['column_name'] == some_value] details in: http://stackoverflow.com/questions/17071871/sele ...
- Oracle数据库学习笔记
创建表的同时插入数据:create table zhang3 as select * from zhang1;create table zhang3(id,name) as select * from ...
- MySQL: @variable vs. variable. Whats the difference?
MySQL: @variable vs. variable. Whats the difference? up vote351down votefavorite 121 In another qu ...
- LINQ to SQL Select查询
1. 查询所有字段 using (NorthwindEntities context = new NorthwindEntities()) { var order = from n in contex ...
随机推荐
- 跟我学设计模式视频教程——适配器模式,适配器模式VS装饰模式
课程视频 适配器模式 适配器模式VS装饰模式 唠嗑 课程笔记 课程笔记 课程代码 课程代码 新课程火热报名中 课程介绍
- log4j.propertie配置具体解释
1.log4j.rootCategory=INFO, stdout , R 此句为将等级为INFO的日志信息输出到stdout和R这两个目的地,stdout和R的定义在以下的代码,能够随意起名.等级可 ...
- lambda的函数式接口
函数式接口就是只包含一个抽象方法的接口A(不包括默认抽象方法,但包括继承来的方法):这个接口用来作为一个可变作用的方法B的参数.函数式接口的抽象方法的参数类型和返回值就是一套签名,这个签名叫做函数描述 ...
- 闭包(closure)与协程共用时要注意的事情
闭包是一种能够让你用非常舒服的方式来编程的小技巧,Go也支持闭包. 假设从来没有接触过闭包,想在一開始就弄懂什么是闭包(closure)是非常困难的,就像递归一样,直到你真正写过.用过它,你才干真正的 ...
- 343D/Codeforces Round #200 (Div. 1) D. Water Tree dfs序+数据结构
D. Water Tree Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each ...
- Python的Flask框架入门-Ubuntu
全文请见tuts code:An Introduction to Python's Flask Framework Flask是Python一个小而强大的web框架.学起来简单,用起来也容易,能够帮你 ...
- PIC18F26K20
Clock Four Crystal modes, Two External clock modes, Two RC Oscillator, Internal oscillator, PLL
- POJ 3273 Monthly Expense 【二分答案】
题意:给出n天的花费,需要将这n天的花费分成m组,使得每份的和尽量小,求出这个最小的和 看题目看了好久不懂题意,最后还是看了题解 二分答案,上界为这n天花费的总和,下界为这n天里面花费最多的那一天 如 ...
- map循环遍历
data.map(function(item){ item.show = false; //将拿到的data循环给每一项添加show属性 });
- axios使用方法
npm install axios 创建文件夹api/index.js import axios from 'axios'; let http = axios.create({ baseURL: '' ...