select A.Id,A.Email,(
select C.Email from [nopCommerce].[dbo].[Customer] C
left join [nopCommerce].[dbo].CustomerAddresses CA
on C.Id=CA.Customer_Id where A.Id=CA.Address_Id) as 'Email2' from [nopCommerce].[dbo].[Address] A

如此有效。

update [nopCommerce].[dbo].[Address] set Email=(
select C.Email from [nopCommerce].[dbo].[Customer] C
left join [nopCommerce].[dbo].CustomerAddresses CA
on C.Id=CA.Customer_Id where Id=CA.Address_Id)

如此无效 数据是改了,但完全不是要的结果

update [nopCommerce].[dbo].[Address] set Email=(
select C.Email from [nopCommerce].[dbo].[Customer] C
left join [nopCommerce].[dbo].CustomerAddresses CA
on C.Id=CA.Customer_Id where [nopCommerce].[dbo].[Address] .Id=CA.Address_Id)

只有在内部连接上

改为[nopCommerce].[dbo].[Address] .Id 才有效

DECLARE @a TABLE (Id INT, NewEmail NVARCHAR(200))
--INSERT INTO @a( Id, NewEmail)VALUES(1,'abc')

INSERT INTO @a( Id, NewEmail)
select A.Id,(
select C.Email from [nopCommerce].[dbo].[Customer] C
left join [nopCommerce].[dbo].CustomerAddresses CA
on C.Id=CA.Customer_Id where A.Id=CA.Address_Id) as 'Email2' from [nopCommerce].[dbo].[Address] A

update [nopCommerce].[dbo].[Address] set Email=(
select T.NewEmail from @a T where [nopCommerce].[dbo].[Address].Id=T.Id)

update [nopCommerce].[dbo].[Address] set Email=(
select C.Email from [nopCommerce].[dbo].[Customer] C
left join [nopCommerce].[dbo].CustomerAddresses CA
on C.Id=CA.Customer_Id where Id=CA.Address_Id)

select A.Id,A.Email,(
select C.Email from [nopCommerce].[dbo].[Customer] C
left join [nopCommerce].[dbo].CustomerAddresses CA
on C.Id=CA.Customer_Id where A.Id=CA.Address_Id) as 'Email2' from [nopCommerce].[dbo].[Address] A

SQL update 关联更改,内部需要引用表名的更多相关文章

  1. SQL Server 2008 R2——根据数据查找表名和字段名 根据脏数据定位表和字段

    =================================版权声明================================= 版权声明:原创文章 谢绝转载  请通过右侧公告中的“联系邮 ...

  2. Mysql动态sql语句,用当前时间做表名

    在mysql备份操作中, 我们可能要使用表名和当前时间来做为备份表的名称,但是MySQL在存储过程中不支持使用变量名来做表名或者列名. 例如:有一个表"user",我需要备份一份, ...

  3. C#通过SQL 添加,删除,或者修改表名。

    这是我在 https://forums.asp.net/t/2106051.aspx?Create+Dynamic+table+in+SQL+using+C+ 的回复,如果其他人需要,可以参考 如果你 ...

  4. SQL Server查询数据库中所有的表名及行数

    SELECT a.name, b.rows FROM sysobjects AS a INNER JOIN sysindexes AS b ON a.id = b.id WHERE (a.type = ...

  5. 获取oracle 表字段,表名,以及主键之类等等的信息

    数据库版本号:select * from v$version 数据库名:select * from v$instance 注意: 我在C#项目中查询语句的时候报“ORA-00911: 无效字符” 的错 ...

  6. 获取oracle 表字段,表名,以及主键之类等等的信息。

    获取表名:  Oracle的user_talbes用于记录了用户表信息. select * from user_tables  获取某个表的字段: USER_TAB_COLS中记录了用户表的列信息.下 ...

  7. linux下mysql的表名问题

    最近从win转移到了linux,在本机跑好的程序但在linux下一个SQL语句报了错误,发现是表名未找到,错误原因是在linux下mysql的表名是严格区分大小写的.. MYSQL在LINUX下数据库 ...

  8. oracle之按表名查询表字段结构

    工作中查看oracle表结构, 1,pl/sql或其他开发工具可以输入表名然后ctr+点击表名就可以看见表结构: 2,表字段过多,如果给第三方截图看比较麻烦,得截好几次,容易看眼花,可以查询如下sql ...

  9. SQL实现新增表,表名更改,列名更改,约束更改等

    --新建表: CREATE TABLE TABLENAME ( ID INT IDENTITY (1,1) PRIMARY KEY , NAME VARCHAR(50) DEFAULT 'HELLO' ...

随机推荐

  1. RedHat6.5升级内核

    redhat6.5 升级内核 1.导入key rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org 2.安装elrepo的yum源 rp ...

  2. 《Docekr入门学习篇》——Docker仓库harbor

    Harbor Harbor仓库介绍 我们在日常Docker容器使用和管理过程中,渐渐发现部署企业私有仓库往往是很有必要的, 它可以帮助你管理企业的一些敏感镜像, 同时由于Docker Hub的下载速度 ...

  3. ubuntu16cuda8 cuda9.0 共存

    https://blog.csdn.net/lovebyz/article/details/80704800 转载

  4. 关于nginx配置的一个报错connect() to unix:/tmp/php-cgi.sock failed (2: No such file or directory)

    针对配置php的情况: linux服务器一般提示这个 connect() to unix:/tmp/php-cgi.sock failed (2: No such file or directory) ...

  5. Xcode7 HTTP请求问题

    问题: “Application Transport Security has blocked a cleartext HTTP (http://) resource load since it is ...

  6. Gitbook在 Mac 环境上的安装及使用

    一.在 Mac 环境上搭建 gitbook #.安装node.js,在node.js官网下载,直接安装稳定版本. https://nodejs.org/en/ #.检测 node.js 是否安装成功 ...

  7. 一条sql关联删除多张表数据

    现有6张表存在关联关系,要删除主表则其他5张表关联数据也要一块删掉(单条sql多id批量删除) delete t1,t2,t3,t4,t5,t6 FROM rmd_v AS t1 LEFT JOIN ...

  8. django项目班笔记-注册功能

    目录 一.用户模型设计 1.用户表字段分析 2.用户模式设计 二.执行迁移 三.图形验证码 四.将图形验证加入到前端文件中 验证码生成源码:https://files.cnblogs.com/file ...

  9. php对比二个不同的二维数组

    $diff_data = array_filter($data1, function($v) use ($data2) { return ! in_array($v, $data2);});

  10. 4418开发板Android源码整体&单独编译

    内核缺省文件配置之后,Android 目录,运行一键编译脚本“build_android.sh”,如下图所示.注意:本篇文章基于iTOP-4418开发板,编译 Android 必须保证给 Ubuntu ...