给梦一个奔跑的方向!
PDF Print E-mail
568
Written by xlingfairy
Wednesday, 16 December 2009 13:15
假设有表 A,
 
CREATE TABLE A(
ID INT NOT NULL IDENTITY(1,1),
ProductID INT NOT NULL,
RetailerID INT NOT NULL,
Date DATETIME NOT NULL
 
CONSTRAINT A_PK PRIMARY KEY (ProductID, RetailerID, Date)
);
 
我的意思是想让 ProductID, RetailerID 和 Date(不包括小时,分钟等)成为主键。
即:某一天里, retailerID 和 ProductID 是唯一的。
 
SQLServer 里,DateTime 是可以存储 小时、分钟等的,如果程序只有我自己写,我会规范输入的日期,让其只包含日期部分。但要是直接改数据库,就只有通过触发器来规范了。
 
PDF Print E-mail
893
Written by xlingfairy
Thursday, 03 September 2009 10:00
 写过 Oracle 的触发器,写过 MySQL的触发器,SQLServer 的触发器还是头一次写.
Oracle 和 MySQL 触发器里,要得到 新值 旧值,可以用 NEW 和 OLD 两个关键字,但是SQLServer 里却不能这样.
 
百度了很久,都是一些不经过大脑的转载.
还好,我在帮助文件里查到了 INSERTED 这个关键字.
 
CREATE TRIGGER CSK_T_GoodSearchKeywords ON CSK_Store_GoodSearchKeywords FOR INSERT, UPDATE AS 
BEGIN
Last Updated ( Thursday, 03 September 2009 10:22 )
 
PDF Print E-mail
613
User Rating: / 1
PoorBest 
Written by xlingfairy
Wednesday, 08 July 2009 22:41
INSERT INTO CSK_Store_Retailer_Change_Rate
SELECT *
FROM 
OPENDATASOURCE ('Microsoft.Jet.OLEDB.4.0' , 'Data Source=d:\retailerChange.xls;Extended Properties=Excel 8.0')...[Sheet1$]
 
启用Ad Hoc Distributed Queries:
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure

使用完成后,关闭Ad Hoc Distributed Queries:
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure

SELECT *
FROM OPENDATASOURCE(
'SQLOLEDB',
'Data Source=ServerName;User ID=sa;Password=sa'
).DataBaseName.dbo.Table
select * from openrowset( 'SQLOLEDB ', 'IP地址'; '用户名'; '密码',数据库名.dbo.表名)
Last Updated ( Friday, 17 July 2009 10:39 )
 
PDF Print E-mail
1233
User Rating: / 1
PoorBest 
Written by xlingfairy
Wednesday, 08 July 2009 22:39
经常写一些联合查询,联合一多了,代码就成倍的增加,时间一长,连我自己也看不懂到底是什么意思了。
做Oracle 的时候,就看到有个 WITH, 不过没有深入的看,就会 WITH 一个出来。
前几天又想用这个WITH,于是细心的查查了,原来 WITH 多个 联系查询的语法是这样的:
WITH PPC AS (
  SELECT
    A.*
  FROM(
    SELECT
      ROW_NUMBER() OVER (PARTITION BY PPCMemberID ORDER BY CreatedOn DESC) AS RN,
      PPCMemberID,PPC,DailyBudget,CreatedOn
    FROM
  CSK_Store_PPCBudgetHistory
  ) A
  WHERE RN = 1
),
PPCM AS (SELECT PPCMemberID,RetailerID FROM CSK_Store_PPCMember),
RP AS (SELECT RetailerID,ProductID,PurchaseURL FROM CSK_Store_RetailerProduct WHERE ProductID = 1337534)
SELECT
  RP.*,
  PPCM.PPCMemberID,
  PPC.PPC,PPC.DailyBudget
FROM
  RP LEFT JOIN
  PPCM ON RP.RetailerID = PPCM.RetailerID LEFT JOIN
  PPC ON PPC.PPCMemberID = PPCM.PPCMemberID
 
PDF Print E-mail
849
User Rating: / 2
PoorBest 
Written by xlingfairy
Thursday, 21 May 2009 17:57
 06年,司令做Oracle的时候,对分析函数表现出了极大兴趣。于是有了下面这些日志:
 
不要怀疑,司令就是我啦。
 
SQLServer 我只是05年用过一年,除了06年,我都是在用MySQL。
现在没机会用Oracle ,但是却一直梦着它,梦想着某一天在用上它。
 
SQLServer 2005 里面也提供了分析函数,有叫窗口函数的。
看下面的示例:
 
Last Updated ( Thursday, 21 May 2009 18:09 )
 

Popular Contents

Recommend

Site Info

Members : 1
Content : 143
Web Links : 7
Content View Hits : 113065

Links

 

Trace