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 ...
随机推荐
- WinServer-IIS-请求筛选
这个实在太多了,可以比较好的控制网站的访问 来自为知笔记(Wiz)
- [博弈] hdu 3683 Gomoku
题意: 两个人下五子棋.给你现有棋盘,推断在三步之内的胜负情况. 输出分为几种. 1.棋盘不合法 2.黑或白在第一步赢下在(x,y)点,多个输出x最小的.y最小的. 3.输在第二步 4.黑或白在第三步 ...
- lambda的函数式接口
函数式接口就是只包含一个抽象方法的接口A(不包括默认抽象方法,但包括继承来的方法):这个接口用来作为一个可变作用的方法B的参数.函数式接口的抽象方法的参数类型和返回值就是一套签名,这个签名叫做函数描述 ...
- C语言学习小记
2013年1月31日 今天试着编程为报文去头去尾. #include #include #define MAX_LENTH 1024 int main() { char *path = &quo ...
- 简易Servlet计算器1.0
编写一个简易的Servlet计算器,暂时仅能实现 + - * / % 五种运算 jsp界面: <%@ page language="java" contentType=&qu ...
- HttpWebRequest 表单提交
/// <summary> /// http请求 /// </summary> public static class ZkWebRequestHelp { /// <s ...
- 【原创】rman备份出现ORA-19625
[oracle@sunny stage]$ rman target / Recovery Manager: Release 10.2.0.1.0 - Production on Sun Mar 18 ...
- php创建图像具体步骤
php 的图像处理在验证码是最常见的,下面说下使用php创建图像的具体步骤. 简要说明:PHP 并不仅限于创建 HTML 输出, 它也可以创建和处理包括 GIF, PNG(推荐), JPEG, WBM ...
- SpringBoot学习笔记(14)----应用监控-HTTP方式
SpringBoot提供了三种应用监控的方式 通过HTTP(最简单方便) 通过JMX 通过远程shell 这里就是用最简单的方式来使用SpringBoot的应用监控 首先引入依赖,pom文件如下 &l ...
- js判断浏览器的环境(pc端,移动端,还是微信浏览器)
window.navigator.userAgent用来区分设备和浏览器 <!DOCTYPE html> <html> <head> <meta charse ...