Bruce Xiao 的程序生活

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

随笔分类 -  SQL

摘要:select 语句的执行顺序借用ItZik Ben-Gan、Lubor Kollar、Dejan Sarka所著的《Sql Server 2005 技术内幕:T-SQL查询》的一段话足以说明:(8) select (9) distinct (11) (1)from(3) join (2) on (4) where (5)group by (6) with {cube|rollup}(7)having(having_condition)(10) order by 从这个顺序可以看出,所有的查询语句都是从from开始执行的。在执行过程中,每个步骤都会为下一个步骤生成一个虚拟表,这个虚拟表将作为.. 阅读全文
posted @ 2013-10-08 10:45 Bruce Xiao 阅读(378) 评论(0) 推荐(0)

摘要:前日,朋友说要一个表有十几个列要被用来join,问我索引应该怎么建立?给出的答案是:建一个聚集索引(在最常用的列上而且重复得很少的列上),在再几个比较用得多的列上建非聚集索引(由于手机上回复,懒得写太多的字咯..),不知道说得对不对哦,请达人请正.现作以下的整理,留作以后参考吧!!1、索引分类:按照存储方式分为:聚集与非聚集索引按照维护与管理索引角度分为:唯一索引、复合索引和系统自动创建的索引2、... 阅读全文
posted @ 2007-12-18 16:47 Bruce Xiao 阅读(1224) 评论(9) 推荐(0)

摘要:在实际的开发过程中,字符的操作会很多,很多时候知道这个函数但又不知道具体怎么应用,所以整理了一下,以备查用.Oracle自带的字符函数(包括10g):/Files/Bluer/StringFuntion-Oracle.doc 阅读全文
posted @ 2007-11-30 10:46 Bruce Xiao 阅读(490) 评论(0) 推荐(0)

摘要:ORACLE中表test(a,b,c)有记录如下: A BC 1 XXX 01 2 YYY 01 3 KKK 02 4 III 02 。。。。 把C相同的B根据序号A串联起来,即得到这样的结果 B C XXXYYY 01 KKKIII 02 create table test(a int,b varchar2(100),c varchar2(100));insert into testselect... 阅读全文
posted @ 2007-11-30 09:35 Bruce Xiao 阅读(387) 评论(0) 推荐(0)

摘要:CREATE PROCEDURE [dbo].[GetUsers] @RowIndex int,----當前指定的頁數 @RecordCount int----每頁顯示的記錄數ASBEGIN SET NOCOUNT ON; With VUsers as ( select *,row_number() over (order by UserID desc) as RowNum from MyUser... 阅读全文
posted @ 2007-07-12 11:01 Bruce Xiao 阅读(317) 评论(0) 推荐(0)

摘要:--Create the table and insert values as portrayed in the above example.CREATE TABLE pvt (VendorID int, Emp1 int, Emp2 int,Emp3 int, Emp4 int, Emp5 int)GOINSERT INTO pvt VALUES (1,4,3,5,4,4)INSERT INTO... 阅读全文
posted @ 2007-06-18 09:03 Bruce Xiao 阅读(453) 评论(1) 推荐(0)

摘要:declare @Param1 varchar(100)set @Param1 ='10,20,30,40'create table #split (field1 varchar(20))declare @tstr varchar(1000)set @tstr=@Param1while charIndex(',',@tstr)>0begin insert into #split (field... 阅读全文
posted @ 2007-05-28 10:58 Bruce Xiao 阅读(225) 评论(0) 推荐(0)

摘要:CREATE PROC pr_GetLastJobDay@Date DATETIMEASdeclare @lastday datetime--得到這個月的最後一天set @lastday=dateadd(dd,-day(@date),dateadd(mm,1,@date))while datename(weekday,@lastday) ='Saturday' or datename(weekda... 阅读全文
posted @ 2007-04-20 11:40 Bruce Xiao 阅读(500) 评论(0) 推荐(0)

摘要:1. 先建立 FileGroups, 點擊 Add 輸入 Group Name 2. 再建立每個 FileGroup 對應的 Database File, 點擊Add 輸入Logical Name并選擇FileGroup 3. 建立 Partion Function, 定義分區的規則, 一般欄位選擇數值型最好, 其它型的沒有太大意義 create partition function Pla... 阅读全文
posted @ 2006-12-29 18:26 Bruce Xiao 阅读(234) 评论(0) 推荐(0)

摘要:create table #tb (id int,User1 nvarchar(100),ProductName nvarchar(100),AddTime smalldatetime)---第一次:每一个用户按最新日期取一条排到前面 ---第二次:其它产品直接按日期最新日期排! insert into #tb select 1, 'A' , 'AAB', ... 阅读全文
posted @ 2006-11-03 09:06 Bruce Xiao 阅读(252) 评论(0) 推荐(0)

摘要:示例1 Code name Value 1 name1 20 ... 阅读全文
posted @ 2006-10-13 20:57 Bruce Xiao 阅读(393) 评论(0) 推荐(0)