随笔分类 -  T-SQL

T-SQL编程的基础知识与示例
SQL TUNNING
摘要:In a Nested Loops Join, for example, the first accessed table is called the outer table and the second one the inner table. In a Hash Join, the first ... 阅读全文

posted @ 2015-01-16 19:48 tneduts 阅读(232) 评论(0) 推荐(0)

DB String Split sample
摘要:以sqlserver为例进行说明,代码稍加修改,可以用于ORACLE。字符串的拆分和聚合是数据库开发人员比较常见的任务。关于字符串的聚合和拆分,sqlserver的标准解决方案是for xml path.oracle 11g提供了listagg函数方便获取。今天就字符串的拆分进行分析。重点在于思路。... 阅读全文

posted @ 2015-01-14 21:22 tneduts 阅读(795) 评论(1) 推荐(0)

Sql-oracle and sqlserver differences
摘要:1.string contact operatorSqlserver use + or contact(sqlserver 2012)In oracle, you can also use contact, but you can not used + to contact string, you ... 阅读全文

posted @ 2014-11-26 07:54 tneduts 阅读(775) 评论(0) 推荐(0)

SQL-一道特殊的字符串分解题目
摘要:本题不是一道直接的字符串拆解, 应用场景如下,表中有一个字段,是表示事件受影响的国家集合,使用逗号进行分隔,不幸的是,居然发现有些国家本身就带有逗号,这样在规范化的时候,如何准确地找到这些国家呢? 以下的代码是有一定限制的。但基本上够用。 下面的代码使用到了分析函数lag和lead还有cte,sql... 阅读全文

posted @ 2014-11-22 09:48 tneduts 阅读(971) 评论(0) 推荐(0)

Merge compare columns when null
摘要:Key words: merge compare columnswhen we contact merge sql in ETL,When we update some columns we should compare the value change or not.We always write... 阅读全文

posted @ 2014-10-22 12:42 tneduts 阅读(376) 评论(0) 推荐(0)

Vertica 项目常用代码
摘要:1.查看目录下面有多少文件数ls -l |grep "^-"|wc -l 思路很明显了,ls后通过grep进行过滤判断是文件还是文件夹,如果是判断文件夹,可以使用ls -l |grep "^d"|wc -l2.copy命令连接数据库 并分批导入文件到数据库中下面是我的示例代码,可以分批把数据导入到数... 阅读全文

posted @ 2014-04-25 18:28 tneduts 阅读(1812) 评论(1) 推荐(0)

数据按时间拆开分批处理示例
摘要:我现在的问题是有一个大的事实表,已经有数十亿条数据,过来的临时表需要merge进去. 临时表的大小也不确定,可能上十亿也可能只有几百几千万而已.如果直接让这两个表merge起来,则需要很大的内存来进行处理.所以我就想着把数据进行按时间拆分的处理,然后merge进去,拆分的条件是如果临时表的数据量大于... 阅读全文

posted @ 2014-04-23 16:43 tneduts 阅读(595) 评论(0) 推荐(0)

TSQL点滴
摘要:Q1.什么是bookmark lookup?非聚集索引中叶结点存储的是index keyword 和 rowid(heap table) 或 clusterindex key. 如果查询使用了非聚集索引,但是select中包含了非聚集索引中没有的列,则会使用bookmark lookup ,即返回到聚集索引或page中去找原始数据.如果数据量很大,这样会造成很大的性能损耗,所以建议改成覆盖索引或其他方式. 阅读全文

posted @ 2014-03-28 06:59 tneduts 阅读(167) 评论(0) 推荐(0)

Excel demo in SSIS
摘要:需求如下,把异常数据从sqlserver数据库中取出来,然后导入到xls中去,然后再发邮件给用户,把xls作为附件发送。需要的示例数据表: /*create table abnormaldata(rowid bigint , rowname nvarchar(20) ,rowvalue nvarchar(100));insert into abnormaldata(rowid,rowname,rowvalue) values(1,'studentname','studentA');insert into abnormaldata(rowid,rowname,ro 阅读全文

posted @ 2014-03-16 15:55 tneduts 阅读(410) 评论(0) 推荐(0)

MSBI BigData demo—sqoop import
摘要:--sp_readerrorlog 读取错误的信息记录 exec sys.sp_readerrorlog 0, 1, 'listening'查看端口号首先hadoop环境要配置完毕,并检验可以正常启动并使用.在hadoop的namenode上安装sqoop,并设置相关的环境变量.如HADOOP_HOME也是需要先配置好的.否则提示找不到hadoop,Error: /usr/lib/hadoop does not exist!我的实验环境是apache hadoop 1.0.4 ,java 1.7, sqoop 1.4.在本机上安装了三台centos的linux系统作为小集群测试 阅读全文

posted @ 2013-12-28 12:54 tneduts 阅读(975) 评论(0) 推荐(0)

BI Project Managerment
摘要:Design doc is the meta data of the code. The project management plan is crucial to your project since it is the basis on which the project will be measured. It can be used to aid in communication between stakeholders and to define the content and timing of project reviews. Here are some elements tha 阅读全文

posted @ 2013-12-26 13:55 tneduts 阅读(409) 评论(0) 推荐(0)

再学TSQL基础--单表查询
摘要:本内容是我学习tsql2008的阅读笔记什么是关系模型?若对列创建唯一约束,背后中的物理机制也是创建了一个唯一索引.SQL语句的逻辑解析顺序是FROMWHEREGROUP BYHAVINGSELECTOVERDISTINCTTOPORDER BY如果SELECT语句中涉及到分组,则后面的select order having的操作对象将是分组。所有聚合函数都会忽略NULL值,只有count(*)除外。带有order by子句的查询被ANSI称之为游标。表表达式不能处理游标。TOP 是TSQL所特有的,用来限制返回的行数或百分比。开窗函数使用OVER子句提供窗口作为上下文,对窗口中的一组值进行操 阅读全文

posted @ 2013-12-26 09:42 tneduts 阅读(247) 评论(0) 推荐(0)

MSBI--enlarge the DW database table volume
摘要:我们在学习MSBI的时候,经常会使用官方提供的Adventureworks和AdventureworksDW示例数据库,但是官方提供的数据量有点小,以DW为例,Factinternetsales只有不到七万行的数据,我们很难做某些测试,譬如说想对事实表做一个分区测试,测试CUBE性能等.为此,我想以FactInternetSales表为入口,扩大它的数据量到数亿条.经过分析,我觉得只要把理解主键是怎么生成的,以及orderdatekey,duedatekey,shipdatekey修改下,随机生成productkey与customerkey(其实是随机从这两个维表中抽取key),基本上就可以装 阅读全文

posted @ 2013-12-06 08:27 tneduts 阅读(859) 评论(2) 推荐(1)

Sql Practice 2
摘要:之前写了一个SP用来向dimention table插入0 -1 dummy row的值,但今天在process adventureworksdw2008示例数据库的时候报错,查看了一下,是因为自己当时实验时插入的数据有问题,就想清除掉这些数据.本想使用sp_Msforeachtable 但一直报错 不能识别$identity.exec sp_MSforeachtable @command1="delete from '?'",@whereand='and $identity < 1'只好写下了如下的代码:declare @tables 阅读全文

posted @ 2013-11-30 06:53 tneduts 阅读(271) 评论(0) 推荐(0)

Sql practice
摘要:employee表 数据准备use tempdbgo if OBJECT_ID('employee') is not nulldrop table employee;with employee(id,name,salary,manager_id) as(select * from(values(1,'John',300,3),(2,'Mike',200,3),(3,'Sally',550,4),(4,'Jane',500,7),(5,'Joe',600,7),(6,'Dan',600 阅读全文

posted @ 2013-11-30 06:36 tneduts 阅读(387) 评论(1) 推荐(0)

Create trace with tsql
摘要:we can use sql server profiler to create a trace with a UI, sometimes we want to do this automatically, such as in a agent job. so we need another way.in fact ,the sql server 2008 can expert the tsql code for the trace in the file menu.USE [master]GO/****** Object: StoredProcedure [dbo].[StartProfi. 阅读全文

posted @ 2012-05-04 09:07 tneduts 阅读(221) 评论(0) 推荐(0)

using xml in sql server(转)
摘要:http://pratchev.blogspot.com/2007/06/shredding-xml-in-sql-server-2005.htmlUsing XML data has many applications. In databases in particular it can be used for passing parameters from client applications, exchange data between SQL modules, or storing details in XML columns. SQL Server 2005 offers new 阅读全文

posted @ 2012-02-08 16:19 tneduts 阅读(155) 评论(0) 推荐(0)

GAPSAND ISLANDS
摘要:寻找列中的gap.其实在inside sql server 2008中有专门的讨论。create table test (id int primary key); goinsert into values (1),(2),(3),(4),(5),(6),(8),(9),(11),(12),(13),(14),(18),(19)查找出结果为:missingbefore missingafter6 891114 18以下为sql:第一种方法使用了一个辅助表temp(tid int primarykey).在里面插入了一定量的数据。WITH CTE AS( SELECT TID FROM temp. 阅读全文

posted @ 2011-12-21 15:33 tneduts 阅读(281) 评论(3) 推荐(0)

(转)sqlserver 锁查看
摘要:--处理死锁 查看当前进程,或死锁进程,并能自动杀掉死进程 因为是针对死的,所以如果有死锁进程,只能查看死锁进程 当然,你可以通过参数控制,不管有没有死锁,都只查看死锁进程--邹建 2004.4----调用示例 exec p_lockinfo--create proc p_lockinfo@kill_lock_spid bit=1, --是否杀掉死锁的进程,1 杀掉, 0 仅显示@show_spid_if_nolock bit=1 --如果没有死锁的进程,是否显示正常进程信息,1 显示,0 不显示asdeclare @count int,@s nvarchar(1000),@i intsel. 阅读全文

posted @ 2011-11-29 12:30 tneduts 阅读(270) 评论(0) 推荐(0)

TOP AND APPLY
摘要:select top(n) from table order by fieldname如果根据fieldname不能确定顺序,则会产生不稳定的输出.若使用 with ties 查询结果集会包含额外的行,这些额外行在排列上的值与top最后一行排列的值相同.apply 运算符有两种形式:cross apply and outer apply.类似 inner join and left outer join.可以把外部查询的列作为参数传递给表值函数.使用top and apply 组合解决常见的问题1.每组中的top(n)方案一:使用 row_number() over (partition by 阅读全文

posted @ 2011-09-03 08:44 tneduts 阅读(197) 评论(0) 推荐(0)

导航