Reference: http://blogs.msdn.com/b/felixmar/archive/2011/08/29/partitioning-amp-archiving-tables-in-sql-server-part-2-split-merge-and-switch-partitions.aspx In the 1st part of this post, I explained how to create a partitioned table using a partition…
Reference: http://blogs.msdn.com/b/felixmar/archive/2011/02/14/partitioning-amp-archiving-tables-in-sql-server-part-1-the-basics.aspx Database partitioning is a feature available in SQL Server(version 2005 and Up) which lets you split a table among m…
Temporary tables in SQL Server…
SQL Server 2008中的MERGE语句能做很多事情,它的功能是根据源表对目标表执行插入.更新或删除操作.最典型的应用就是进行两个表的同步. 下面通过一个简单示例来演示MERGE语句的使用方法,假设数据库中有两个表Product及ProductNew,我们的任务是将Product的数据同步到ProductNew(当然同步可能是每天通过Job来自动完成的,在此我们只关注MERGE的使用). 以下SQL创建示例表: --源表 CREATE TABLE Product (     Produc…
OK,就像标题呈现的一样,SQL Server 2008中的MERGE语句能做很多事情,它的功能是根据源表对目标表执行插入.更新或删除操作.最典型的应用就是进行两个表的同步. 下面通过一个简单示例来演示MERGE语句的使用方法,假设数据库中有两个表Product及ProductNew,我们的任务是将Product的数据同步到ProductNew(当然同步可能是每天通过Job来自动完成的,在此我们只关注MERGE的使用). 以下SQL创建示例表: --源表 CREATE TABLE Product…
详细链接:https://shop499704308.taobao.com/?spm=a1z38n.10677092.card.11.594c1debsAGeak--方法0:动态SQL法 declare @s varchar(),@sql varchar() set @s='1,2,3,4,5,6,7,8,9,10' set @sql='select col='''+ replace(@s,',',''' union all select ''')+'''' PRINT @sql exec (@…
Create function [dbo].[split] ( ), ) ) )) as begin declare @i int set @SourceSql=rtrim(ltrim(@SourceSql)) set @i=charindex(@StrSeprate,@SourceSql) begin )) ,len(@SourceSql)-@i) set @i=charindex(@StrSeprate,@SourceSql) end if @SourceSql<>'' insert @t…
CREATE FUNCTION [dbo].[F_split] ( ), ) ) , ), f )) --实现split功能 的函数 AS BEGIN DECLARE @i INT SET @SourceSql = RTRIM(LTRIM(@SourceSql)) SET @i = CHARINDEX(@StrSeprate, @SourceSql) BEGIN ) ) , LEN(@SourceSql) -@i) SET @i = CHARINDEX(@StrSeprate, @SourceS…
--Comparing data between two tables in SQL Server --Create two Tables-- CREATE TABLE TableA(ID Int, ProuctName Varchar(256)) GO CREATE TABLE TableB(ID Int, ProuctName Varchar(256)) GO INSERT INTO TableA VALUES(1,'A') INSERT INTO TableA VALUES(2,'B')…
Complete list of Microsoft SQL Server trace flags (585 trace flags) REMEMBER: Be extremely careful with trace flags, test in your test environment first. And consult professionals first if you are the slightest uncertain about the effects of your cha…