1 删除整张表的数据,并还原自增长值
TRUNCATE TABLE TbWeixinActivity

2 3张表左连接
select a.ID,c.Name,b.nickname,a.CreateDate from TbUserJoin as a left join tbWX_User as b on a.WeChatID=b.openid left join TbUnitActivity as c on a.ActivityID=c.ID where a.IsValid=1 order by a.CreateDate asc //where条件和排序可以根据需求加或不加

3 视图
2 3张表左连接
select a.ID,c.Name,b.nickname,a.CreateDate from TbUserJoin as a
left join tbWX_User as b on a.WeChatID=b.openid
left join TbUnitActivity as c on a.ActivityID=c.ID

4 把表中的数据复制到另一个数据库中
select *
into TbPersonRegister //目标数据库
from [wxlodc20150708].dbo.TbPersonRegister //如果报错,说明目标数据库已经有了这个表,把它删除即可

5 使用触发器进行级连删除
create trigger triggerPersonDelete
on person
instead of DELETE
as
begin
declare @pId int
select @pId=id from deleted
--删除tel
delete Tel where PersonID=@pId
--删除person 主表
delete person where id=@pId
end

SQL把表中的数据复制到另一个数据库中的更多相关文章

  1. SQL将一个数据库中的数据复制到另一个数据库中

    复制表结构 首先,打开并连接Sql Server,在源数据库Source_db(源数据库名称)上右键,然后依次点击"编写表脚本为"→"CREATE到"→&quo ...

  2. SQL SERVER 将一个数据库中的表和数据复制到另一个数据库中

    第一种情况:将A数据库.dbo.A表的数据追加到B数据库.dbo.B表中 (条件:此时B数据库中已创建好了B表) insert into B数据库.dbo.B表 select * from A数据库. ...

  3. SQL数据库中把一个表中的数据复制到另一个表中

    1.如果是整个表复制表达如下: insert into table1 select  * from table2 2.如果是有选择性的复制数据表达如下: insert into table1(colu ...

  4. sqlserver触发器如何将一个库中的数据插入到另外一个库中

    需求:实现的功能就是,查询当前表的所有信息,插入到另外一个库中(同一台机器,同一个SqlServer) 解决:insert into dB2.dbo.TB2 select * from db1.dbo ...

  5. mysql 将一个表中的数据复制到另一个表中,sql语句

    1.表结构相同的表,且在同一数据库(如,table1,table2) Sql :insert into table1 select * from table2 (完全复制) insert into t ...

  6. Sql Server两个数据库中有一张表的结构一样,怎么快速将一张表中的数据复制到另一个表中

    1,下面这句会把表2数据删除,然后把表1复制到表一,两表内容一样 SELECT * into 表2 FROM 表1 2,这句只追加,不删除表2的数据 insert into 表1 select * f ...

  7. 用Java 实现一个表中的数据复制到另一个表中

    string sql = "insert into tbl1(s1,s2,s3) select t.t1,t.t2,t.t3 from tab2 t";再用jdbc或者hibern ...

  8. sql 从一个库中取某个表的数据导入到另一个库中相同结构的表中

    sql 2008 从一个库中把 某个表中的数据导入到另一个库中的具有相同结构的表中 use 库1 go insert into  库1.dbo.表1  select * from  库2.dbo.表1 ...

  9. (转)SqlServer将数据库中的表复制到另一个数据库

    本文为转载地址为:http://jingyan.baidu.com/article/d5c4b52bc5c102da570dc547.html 复制表结构 在使用SqlServer的过程中,我们可能需 ...

随机推荐

  1. lucene 建立索引的不同方式

    1.创建一个简单的索引: package lia.meetlucene; import java.io.File; import org.apache.lucene.document.Document ...

  2. java语法基础思维导图

  3. 客户端显示Not yet reported

    No.1: IIS, WSUS, 加域的顺序,不过貌似关系不大,按照这个顺序就行了.   No.2: KB2734608, KB2720211的影响,3.2.7600.256 (KB2734608), ...

  4. Eclipse学习记录

    设置背景色:http://jingyan.baidu.com/article/2a138328b5d9ea074a134fc7.html 项目文件说明:http://www.cnblogs.com/p ...

  5. StringUtils cannot be resolved

    I am using Java server pages and for using String Manipulations and i am Using StringUtils which i a ...

  6. [ZZ] 在windows上编译Mesa3d opengl32库

    在windows上编译Mesa3d opengl32库 cheungmine http://blog.csdn.net/ubuntu64fan/article/details/8061475 Mesa ...

  7. Guilty Gear Xrd 资源Rip(1)

    资源破解   首先先要下载GGXrd的PS3游戏,用psarc.exe先把游戏解包 http://files.cnblogs.com/TracePlus/psarc.exe.zip   下载UMode ...

  8. 127 2016 int

    Type Storage Minimum Value Maximum Value   (Bytes) (Signed/Unsigned) (Signed/Unsigned) TINYINT 1 -12 ...

  9. Lazarus中system.length说明

    在system单元中我们有Length专门用来获取字符串宽度和数组宽度,下面例子来介绍他的功能. 定义: function Length(   S: AStringType ):Integer; fu ...

  10. Comparable与Comparator

    转载 Comparable与Comparator的区别 (转载) Comparable & Comparator 都是用来实现集合中元素的比较.排序的,只是 Comparable 是在集合内部 ...